blob: fc77d4479b065b243749228aaf408dbf8fed86e6 [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><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><link rel="home" href="manual.html" title="Apache OpenJPA 2.2 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" title="6.&nbsp; Setting the SQL Join Syntax"><div class="titlepage"><div><div><h2 class="title" style="clear: both" id="ref_guide_dbsetup_sql92">6.&nbsp;
Setting the SQL Join Syntax
</h2></div></div></div>
<a class="indexterm" name="d5e11406"></a>
<a class="indexterm" name="d5e11409"></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&nbsp;4.7.&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 class="link" 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 <code class="literal">
JoinSyntax</code> property to set the system's default syntax. The available
values are:
</p>
<div class="itemizedlist"><ul class="itemizedlist" 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&nbsp;9.&nbsp; Runtime Extensions">Chapter&nbsp;9, <i>
Runtime Extensions
</i></a>.
</p>
<div class="example"><a name="ref_guide_dbsetup_sql92_conf"></a><p class="title"><b>Example&nbsp;4.9.&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.10.&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(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>&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>