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:
traditional
: Traditional SQL
join syntax; outer joins are not supported.
database
: The database's native
join syntax. Databases that do not have a native
syntax will default to one of the other options.
sql92
: ANSI SQL92 join syntax.
Outer joins are supported. Not all databases
support this syntax.
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
JPA:
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 ();
JDO:
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 ();