6.  Setting the SQL Join Syntax

Object queries often involve using SQL joins behind the scenes. You can configure OpenJPA to use either SQL 92-style join syntax, in which joins are placed in the SQL FROM clause, the traditional join syntax, in which join criteria are part of the WHERE clause, or a database-specific join syntax mandated by the DBDictionary. OpenJPA only supports outer joins when using SQL 92 syntax or a database-specific syntax with outer join support.

The openjpa.jdbc.DBDictionary plugin accepts the JoinSyntax property to set the system's default syntax. The available values are:

You can change the join syntax at runtime through the OpenJPA fetch configuration API, which is described in Chapter 9, Runtime Extensions .

Example 4.8.  Specifying the Join Syntax Default

<property name="openjpa.jdbc.DBDictionary" value="JoinSyntax=sql92"/>

Example 4.9.  Specifying the Join Syntax at Runtime

import org.apache.openjpa.persistence.jdbc.*; 

... 

Query q = em.createQuery("select m from Magazine m where m.title = 'JDJ'");
OpenJPAQuery kq = OpenJPAPersistence.cast(q);
JDBCFetchPlan fetch = (JDBCFetchPlan) kq.getFetchPlan ();
fetch.setJoinSyntax(JoinSyntax.SQL92);
List results = q.getResultList();