|  | <html><head> | 
|  | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|  | <title>6.  Setting the SQL Join Syntax</title><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="manual.html" title="Apache OpenJPA 3.0 User's Guide"><link rel="up" href="ref_guide_dbsetup.html" title="Chapter 4.  JDBC"><link rel="prev" href="ref_guide_dbsetup_isolation.html" title="5.  Setting the Transaction Isolation"><link rel="next" href="ref_guide_dbsetup_multidb.html" title="7.  Accessing Multiple Databases"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">6.  | 
|  | Setting the SQL Join Syntax | 
|  | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_dbsetup_isolation.html">Prev</a> </td><th width="60%" align="center">Chapter 4.  | 
|  | JDBC | 
|  | </th><td width="20%" align="right"> <a accesskey="n" href="ref_guide_dbsetup_multidb.html">Next</a></td></tr></table><hr></div><div class="section" id="ref_guide_dbsetup_sql92"><div class="titlepage"><div><div><h2 class="title" style="clear: both">6.  | 
|  | Setting the SQL Join Syntax | 
|  | </h2></div></div></div> | 
|  |  | 
|  | <a class="indexterm" name="d5e11562"></a> | 
|  | <a class="indexterm" name="d5e11565"></a> | 
|  | <p> | 
|  | 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 <a class="link" href="ref_guide_dbsetup_dbsupport.html#ref_guide_dbsetup_dbdict" title="Example 4.7.  Specifying a DBDictionary"><code class="classname"> | 
|  | DBDictionary</code></a>. OpenJPA only supports outer joins when using | 
|  | SQL 92 syntax or a database-specific syntax with outer join support. | 
|  | </p> | 
|  | <p> | 
|  | The <a class="link" href="ref_guide_conf_jdbc.html#openjpa.jdbc.DBDictionary" title="6.2.  openjpa.jdbc.DBDictionary"><code class="literal"> | 
|  | openjpa.jdbc.DBDictionary</code></a> plugin accepts the <code class="literal"> | 
|  | JoinSyntax</code> property to set the system's default syntax. The available | 
|  | values are: | 
|  | </p> | 
|  | <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> | 
|  | <p> | 
|  | <code class="literal">traditional</code>: Traditional SQL join syntax; outer joins are | 
|  | not supported. | 
|  | </p> | 
|  | </li><li class="listitem"> | 
|  | <p> | 
|  | <code class="literal">database</code>: The database's native join syntax. Databases that | 
|  | do not have a native syntax will default to one of the other options. | 
|  | </p> | 
|  | </li><li class="listitem"> | 
|  | <p> | 
|  | <code class="literal">sql92</code>: ANSI SQL92 join syntax. Outer joins are supported. | 
|  | Not all databases support this syntax. | 
|  | </p> | 
|  | </li></ul></div> | 
|  | <p> | 
|  | You can change the join syntax at runtime through the OpenJPA fetch | 
|  | configuration API, which is described in <a class="xref" href="ref_guide_runtime.html" title="Chapter 9.  Runtime Extensions">Chapter 9, <i> | 
|  | Runtime Extensions | 
|  | </i></a>. | 
|  | </p> | 
|  | <div class="example" id="ref_guide_dbsetup_sql92_conf"><p class="title"><b>Example 4.9.  | 
|  | Specifying the Join Syntax Default | 
|  | </b></p><div class="example-contents"> | 
|  |  | 
|  | <pre class="programlisting"> | 
|  | <property name="openjpa.jdbc.DBDictionary" value="JoinSyntax=sql92"/> | 
|  | </pre> | 
|  | </div></div><br class="example-break"> | 
|  | <div class="example" id="ref_guide_dbsetup_sql92_fetch"><p class="title"><b>Example 4.10.  | 
|  | Specifying the Join Syntax at Runtime | 
|  | </b></p><div class="example-contents"> | 
|  |  | 
|  | <pre class="programlisting"> | 
|  | 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(); | 
|  | </pre> | 
|  | </div></div><br class="example-break"> | 
|  | </div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ref_guide_dbsetup_isolation.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref_guide_dbsetup.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ref_guide_dbsetup_multidb.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.  | 
|  | Setting the Transaction Isolation | 
|  |  </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 7.  | 
|  | Accessing Multiple Databases | 
|  | </td></tr></table></div></body></html> |