4.7. Setting the SQL Join Syntax

Object queries often involve using SQL joins behind the scenes. You can configure Kodo 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. Kodo only supports outer joins when using SQL 92 syntax or a database-specific syntax with outer join support.

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

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

Example 4.10. Specifying the Join Syntax Default

JPA XML format:

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

JDO properties format:

kodo.jdbc.DBDictionary: JoinSyntax=sql92

Example 4.11. Specifying the Join Syntax at Runtime


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


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


import kodo.jdo.jdbc.*; 


Query q = pm.newQuery (Magazine.class, "title == 'JDJ'");
JDBCFetchPlan fetch = (JDBCFetchPlan) q.getFetchPlan ();
fetch.setJoinSyntax (JDBCFetchPlan.JOIN_SYNTAX_SQL92);
List results = (List) q.execute ();


Skip navigation bar   Back to Top