blob: 070f087a1e47808d8cccea2e33fabaf297680f97 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>6.&nbsp; Setting the SQL Join Syntax</title><link rel="stylesheet" href="css/docbook.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="manual.html" title="Apache OpenJPA User's Guide"><link rel="up" href="ref_guide_dbsetup.html" title="Chapter&nbsp;4.&nbsp; JDBC"><link rel="prev" href="ref_guide_dbsetup_isolation.html" title="5.&nbsp; Setting the Transaction Isolation"><link rel="next" href="ref_guide_dbsetup_multidb.html" title="7.&nbsp; 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.&nbsp;
Setting the SQL Join Syntax
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_dbsetup_isolation.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;4.&nbsp;
JDBC
</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ref_guide_dbsetup_multidb.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ref_guide_dbsetup_sql92"></a>6.&nbsp;
Setting the SQL Join Syntax
</h2></div></div></div><a class="indexterm" name="d0e19732"></a><a class="indexterm" name="d0e19737"></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 href="ref_guide_dbsetup_dbsupport.html#ref_guide_dbsetup_dbdict" title="Example&nbsp;4.6.&nbsp; 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 href="ref_guide_conf_jdbc.html#openjpa.jdbc.DBDictionary" title="6.2.&nbsp; openjpa.jdbc.DBDictionary"><code class="literal">
openjpa.jdbc.DBDictionary</code></a> plugin accepts the the <code class="literal">
JoinSyntax</code> property to set the system's default syntax. The available
values are:
</p><div class="itemizedlist"><ul type="disc"><li><p>
<code class="literal">traditional</code>: Traditional SQL join syntax; outer joins are
not supported.
</p></li><li><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><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 href="ref_guide_runtime.html" title="Chapter&nbsp;9.&nbsp; Runtime Extensions">Chapter&nbsp;9, <i xmlns:xlink="http://www.w3.org/1999/xlink">
Runtime Extensions
</i></a>.
</p><div class="example"><a name="ref_guide_dbsetup_sql92_conf"></a><p class="title"><b>Example&nbsp;4.8.&nbsp;
Specifying the Join Syntax Default
</b></p><div class="example-contents"><pre class="programlisting">
&lt;property name="openjpa.jdbc.DBDictionary" value="JoinSyntax=sql92"/&gt;
</pre></div></div><br class="example-break"><div class="example"><a name="ref_guide_dbsetup_sql92_fetch"></a><p class="title"><b>Example&nbsp;4.9.&nbsp;
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(JDBCFetchPlan.JOIN_SYNTAX_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>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ref_guide_dbsetup.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ref_guide_dbsetup_multidb.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.&nbsp;
Setting the Transaction Isolation
&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;7.&nbsp;
Accessing Multiple Databases
</td></tr></table></div></body></html>