4.6. Setting the SQL Join Syntax
Prev | Chapter 4. JDBC | Next

## 4.6. 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:

- `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.9. 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.10. Specifying the Join Syntax at Runtime

JPA:

    import kodo.persistence.jdbc.*;

    ...

    Query q = em.createQuery ("select m from Magazine m where m.title = 'JDJ'");
    KodoQuery kq = KodoPersistence.cast (q);
    JDBCFetchPlan fetch = (JDBCFetchPlan) kq.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 ();

Prev | Up | Next
4.5. Setting the Transaction Isolation | Home | 4.7. Accessing Multiple Databases