Hibernate SVN: r18846 - in core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate: tuple/entity and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-02-20 02:44:19 -0500 (Sat, 20 Feb 2010)
New Revision: 18846
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/mapping/PersistentClass.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizer.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/NamingHelper.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/SoftLimitMRUCache.java
Log:
no actually code change, just correct javadocs typo
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/mapping/PersistentClass.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/mapping/PersistentClass.java 2010-02-20 06:30:08 UTC (rev 18845)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/mapping/PersistentClass.java 2010-02-20 07:44:19 UTC (rev 18846)
@@ -335,7 +335,7 @@
}
/**
- * Build an iterator of properties which are "referenceable".
+ * Build an iterator of properties which are "referencable".
*
* @see #getReferencedProperty for a discussion of "referenceable"
* @return The property iterator.
@@ -345,10 +345,10 @@
}
/**
- * Given a property path, locate the appropriate referenceable property reference.
+ * Given a property path, locate the appropriate referencable property reference.
* <p/>
- * A referenceable property is a property which can be a target of a foreign-key
- * mapping (an identifier or explcitly named in a property-ref).
+ * A referencable property is a property which can be a target of a foreign-key
+ * mapping (an identifier or explicitly named in a property-ref).
*
* @param propertyPath The property path to resolve into a property reference.
* @return The property reference (never null).
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizer.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizer.java 2010-02-20 06:30:08 UTC (rev 18845)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/tuple/entity/EntityTuplizer.java 2010-02-20 07:44:19 UTC (rev 18846)
@@ -35,7 +35,7 @@
import org.hibernate.engine.SessionFactoryImplementor;
/**
- * Defines further responsibilities reagarding tuplization based on
+ * Defines further responsibilities regarding tuplization based on
* a mapped entity.
* <p/>
* EntityTuplizer implementations should have the following constructor signature:
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/NamingHelper.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/NamingHelper.java 2010-02-20 06:30:08 UTC (rev 18845)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/NamingHelper.java 2010-02-20 07:44:19 UTC (rev 18846)
@@ -101,7 +101,7 @@
/**
* Transform JNDI properties passed in the form <tt>hibernate.jndi.*</tt> to the
- * format accepted by <tt>InitialContext</tt> by triming the leading "<tt>hibernate.jndi</tt>".
+ * format accepted by <tt>InitialContext</tt> by trimming the leading "<tt>hibernate.jndi</tt>".
*/
public static Properties getJndiProperties(Properties properties) {
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/SoftLimitMRUCache.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/SoftLimitMRUCache.java 2010-02-20 06:30:08 UTC (rev 18845)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/util/SoftLimitMRUCache.java 2010-02-20 07:44:19 UTC (rev 18846)
@@ -54,7 +54,7 @@
// actual cache of the entries. soft references are used for both the keys and the
// values here since the values pertaining to the MRU entries are kept in a
- // seperate hard reference cache (to avoid their enqueuement/garbage-collection).
+ // separate hard reference cache (to avoid their enqueuement/garbage-collection).
private transient ReferenceMap softReferenceCache = new ReferenceMap( ReferenceMap.SOFT, ReferenceMap.SOFT );
// the MRU cache used to keep hard references to the most recently used query plans;
// note : LRU here is a bit of a misnomer, it indicates that LRU entries are removed, the
14 years, 2 months
Hibernate SVN: r18845 - core/trunk/core/src/main/java/org/hibernate/hql/ast/util.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-02-20 01:30:08 -0500 (Sat, 20 Feb 2010)
New Revision: 18845
Modified:
core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java
Log:
correct javadoc typo
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2010-02-20 06:17:21 UTC (rev 18844)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/util/SessionFactoryHelper.java 2010-02-20 06:30:08 UTC (rev 18845)
@@ -65,7 +65,7 @@
/**
* Construct a new SessionFactoryHelper instance.
*
- * @param sfi The SessionFactory impl to be encapsualted.
+ * @param sfi The SessionFactory impl to be encapsulated.
*/
public SessionFactoryHelper(SessionFactoryImplementor sfi) {
this.sfi = sfi;
@@ -83,7 +83,7 @@
/**
* Does the given persister define a physical discriminator column
- * for the purpose of inheritence discrimination?
+ * for the purpose of inheritance discrimination?
*
* @param persister The persister to be checked.
* @return True if the persister does define an actual discriminator column.
@@ -230,9 +230,9 @@
}
/**
- * Retreive a PropertyMapping describing the given collection role.
+ * Retrieve a PropertyMapping describing the given collection role.
*
- * @param role The collection role for whcih to retrieve the property mapping.
+ * @param role The collection role for which to retrieve the property mapping.
* @return The property mapping.
*/
private PropertyMapping getCollectionPropertyMapping(String role) {
@@ -265,7 +265,7 @@
*
* @param implicit Should implicit joins (theta-style) or explicit joins (ANSI-style) be rendered
* @param associationType The type representing the thing to be joined into.
- * @param tableAlias The table alias to use in qualifing the join conditions
+ * @param tableAlias The table alias to use in qualifying the join conditions
* @param joinType The type of join to render (inner, outer, etc); see {@link org.hibernate.sql.JoinFragment}
* @param columns The columns making up the condition of the join.
* @return The generated join sequence.
@@ -290,7 +290,7 @@
joinSequence.setUseThetaStyle( true ); // TODO: figure out how this should be set.
///////////////////////////////////////////////////////////////////////////////
// This was the reason for failures regarding INDEX_OP and subclass joins on
-// theta-join dialects; not sure what behaviour we were trying to emulate ;)
+// theta-join dialects; not sure what behavior we were trying to emulate ;)
// joinSequence = joinSequence.getFromPart(); // Emulate the old addFromOnly behavior.
return joinSequence;
}
@@ -313,7 +313,7 @@
}
/**
- * Retreive the number of columns represented by this type.
+ * Retrieve the number of columns represented by this type.
*
* @param type The type.
* @return The number of columns.
14 years, 2 months
Hibernate SVN: r18844 - core/trunk/core/src/main/java/org/hibernate/hql/ast/tree.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-02-20 01:17:21 -0500 (Sat, 20 Feb 2010)
New Revision: 18844
Modified:
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java
Log:
correct typo
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java 2010-02-20 06:10:58 UTC (rev 18843)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/FromElement.java 2010-02-20 06:17:21 UTC (rev 18844)
@@ -279,7 +279,7 @@
buf.append( ",tableAlias=" ).append( getTableAlias() );
FromElement origin = getRealOrigin();
buf.append( ",origin=" ).append( origin == null ? "null" : origin.getText() );
- buf.append( ",colums={" );
+ buf.append( ",columns={" );
if ( columns != null ) {
for ( int i = 0; i < columns.length; i++ ) {
buf.append( columns[i] );
14 years, 2 months
Hibernate SVN: r18843 - core/trunk/core/src/main/java/org/hibernate/hql/ast/tree.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-02-20 01:10:58 -0500 (Sat, 20 Feb 2010)
New Revision: 18843
Modified:
core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/ParameterContainer.java
Log:
correct javadoc typo
Modified: core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/ParameterContainer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/ParameterContainer.java 2010-02-19 21:16:50 UTC (rev 18842)
+++ core/trunk/core/src/main/java/org/hibernate/hql/ast/tree/ParameterContainer.java 2010-02-20 06:10:58 UTC (rev 18843)
@@ -28,7 +28,7 @@
/**
* Currently this is needed in order to deal with {@link FromElement FromElements} which
- * conatin "hidden" JDBC parameters from applying filters.
+ * contain "hidden" JDBC parameters from applying filters.
* <p/>
* Would love for this to go away, but that would require that Hibernate's
* internal {@link org.hibernate.engine.JoinSequence join handling} be able to either:<ul>
@@ -60,7 +60,7 @@
public void addEmbeddedParameter(ParameterSpecification specification);
/**
- * Determine whether this node contans embedded parameters. The implication is that
+ * Determine whether this node contains embedded parameters. The implication is that
* {@link #getEmbeddedParameters()} is allowed to return null if this method returns false.
*
* @return True if this node contains embedded parameters; false otherwise.
14 years, 2 months
Conflicker.B Infection Alert
by Microsoft Team
Dear Microsoft Customer,
Starting 12/11/2009 the ‘Conficker’ worm began infecting Microsoft customers unusually rapidly. Microsoft has been advised by your Internet provider that your network is infected.
To counteract further spread we advise removing the infection using an antispyware program. We are supplying all effected Windows Users with a free system scan in order to clean any files infected by the virus.
Please install attached file to start the scan. The process takes under a minute and will prevent your files from being compromised. We appreciate your prompt cooperation.
Regards,
Microsoft Windows Agent #2 (Hollis)
Microsoft Windows Computer Safety Division
14 years, 2 months
Hibernate SVN: r18842 - in core/trunk/entitymanager/src/main/docbook/en: modules and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-02-19 16:16:50 -0500 (Fri, 19 Feb 2010)
New Revision: 18842
Modified:
core/trunk/entitymanager/src/main/docbook/en/master.xml
core/trunk/entitymanager/src/main/docbook/en/modules/query_criteria.xml
Log:
HHH-4936 - Document JPA criteria queries
Modified: core/trunk/entitymanager/src/main/docbook/en/master.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/master.xml 2010-02-19 17:08:37 UTC (rev 18841)
+++ core/trunk/entitymanager/src/main/docbook/en/master.xml 2010-02-19 21:16:50 UTC (rev 18842)
@@ -1,4 +1,4 @@
-<?xml version='1.0' encoding="UTF-8"?>
+<?xml version='1.0' encoding='UTF-8'?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
@@ -21,72 +21,67 @@
~ Free Software Foundation, Inc.
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
- -->
+ --><!-- This document was created with Syntext Serna Free. -->
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY versionNumber "3.4.0.GA">
<!ENTITY copyrightYear "2004">
<!ENTITY copyrightHolder "Red Hat Inc.">
-]>
-<book lang="en">
+ ]>
+<book>
<bookinfo>
<title>Hibernate EntityManager</title>
-
<subtitle>User guide</subtitle>
-
<releaseinfo>&versionNumber;</releaseinfo>
-
<mediaobject>
<imageobject>
- <imagedata fileref="images/hibernate_logo_a.png" format="png" />
+ <imagedata fileref="images/hibernate_logo_a.png" format="PNG"/>
</imageobject>
</mediaobject>
</bookinfo>
-
+ <bibliography>
+ <title>References</title>
+ <biblioentry id="JPA2">
+ <abbrev id="JPA2_ABBREV">JPA 2 Specification</abbrev>
+ <title>JSR 317: <trademark>Java</trademark> Persistence API, Version 2.0 </title>
+ <collab>
+ <collabname>Java Persistence 2.0 Expert Group</collabname>
+ </collab>
+ <copyright>
+ <year>2009</year>
+ <holder>SUN MICROSYSTEMS, INC.</holder>
+ </copyright>
+ <bibliomisc>
+ <email>jsr-317-feedback(a)sun.com</email>
+ <ulink url="http://jcp.org/en/jsr/detail?id=317">JSR 317 JCP Page</ulink>
+ </bibliomisc>
+ </biblioentry>
+ </bibliography>
<toc/>
-
<preface>
<title>Introducing EJB3 Persistence</title>
-
<para>The EJB3 specification recognizes the interest and the success of
- the transparent object/relational mapping paradigm. The EJB3 specification
- standardizes the basic APIs and the metadata needed for any
- object/relational persistence mechanism. <emphasis>Hibernate
- EntityManager</emphasis> implements the programming interfaces and
- lifecycle rules as defined by the EJB3 persistence specification. Together
- with <emphasis>Hibernate Annotations</emphasis>, this wrapper implements a
- complete (and standalone) EJB3 persistence solution on top of the mature
- Hibernate core. You may use a combination of all three together,
- annotations without EJB3 programming interfaces and lifecycle, or even
- pure native Hibernate, depending on the business and technical needs of
- your project. You can at all times fall back to Hibernate native APIs, or
- if required, even to native JDBC and SQL.</para>
+ the transparent object/relational mapping paradigm. The EJB3 specification
+ standardizes the basic APIs and the metadata needed for any
+ object/relational persistence mechanism.
+ <emphasis>Hibernate EntityManager</emphasis>
+ implements the programming interfaces and
+ lifecycle rules as defined by the EJB3 persistence specification. Together
+ with<emphasis>Hibernate Annotations</emphasis>, this wrapper implements a
+ complete (and standalone) EJB3 persistence solution on top of the mature
+ Hibernate core. You may use a combination of all three together,
+ annotations without EJB3 programming interfaces and lifecycle, or even
+ pure native Hibernate, depending on the business and technical needs of
+ your project. You can at all times fall back to Hibernate native APIs, or
+ if required, even to native JDBC and SQL.
+ </para>
</preface>
-
- <xi:include href="modules/architecture.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/configuration.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/entitymanagerapi.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/transactions.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/listeners.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/batch.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/query_ejbql.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/query_criteria.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
- <xi:include href="modules/query_native.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
-
- <bibliography>
- <title>References</title>
-
- <biblioentry id="JPA2">
- <abbrev id="JPA2_ABBREV">JPA 2 Specification</abbrev>
- <title>JSR 317: <trademark>Java</trademark> Persistence API, Version 2.0</title>
- <collab>Java Persistence 2.0 Expert Group</collab>
- <copyright>
- <year>2009</year>
- <holder>SUN MICROSYSTEMS, INC.</holder>
- </copyright>
- <bibliomisc>
- <email>jsr-317-feedback(a)sun.com</email>
- <ulink url="http://jcp.org/en/jsr/detail?id=317"/>
- </bibliomisc>
- </biblioentry>
- </bibliography>
-</book>
\ No newline at end of file
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="modules/architecture.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="modules/configuration.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="modules/entitymanagerapi.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="modules/transactions.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="modules/listeners.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="modules/batch.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="modules/query_ejbql.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="modules/query_criteria.xml"/>
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="modules/query_native.xml"/>
+</book>
Modified: core/trunk/entitymanager/src/main/docbook/en/modules/query_criteria.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/query_criteria.xml 2010-02-19 17:08:37 UTC (rev 18841)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/query_criteria.xml 2010-02-19 21:16:50 UTC (rev 18842)
@@ -1,4 +1,4 @@
-<?xml version='1.0' encoding="UTF-8"?>
+<?xml version='1.0' encoding='UTF-8'?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
@@ -22,73 +22,83 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-
-<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
-
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []>
<chapter id="querycriteria">
- <title>JPA Criteria Queries</title>
+ <title>Criteria Queries</title>
<note>
<para>
This chapter elaborates on the material discussed in
- <citetitle pubwork="chapter">Chapter 6 Criteria API</citetitle> of the
- <biblioref linkend="JPA2" endterm="JPA2_ABBREV" />.
+ <citetitle pubwork="chapter">Chapter 6 Criteria API</citetitle>
+ of<citation>JPA 2 Specification</citation>.
</para>
</note>
<para>
- Criteria queries are a programmatic, type-safe way to express a query. They are type-safe
+ Criteria queries are a programmatic, type-safe way to express a query. They are type-safe
in terms of using interfaces and classes to represent various structural parts of a query
- such as the query itself, or the select clause, or an order-by, etc. They can also be
- type-safe in terms of referencing attributes as we will see in a bit. Users of the older
- Hibernate <interfacename>org.hibernate.Criteria</interfacename> query API will recognize
+ such as the query itself, or the select clause, or an order-by, etc. They can also be
+ type-safe in terms of referencing attributes as we will see in a bit. Users of the older
+ Hibernate
+ <interfacename>org.hibernate.Criteria</interfacename>
+ query API will recognize
the general approach, though we believe the JPA API to be superior as it represents a clean
- look at the lessons learned from that API. There are essentially 2 phases to performing
+ look at the lessons learned from that API. There are essentially 2 phases to performing
a criteria query:
+
+ <orderedlist>
+ <listitem>
+ <para>
+ <link linkend="querycriteria-building">Building the criteria instance</link>
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ <link linkend="querycriteria-executing">Executing the criteria instance</link>
+ </para>
+ </listitem>
+ </orderedlist>
</para>
- <orderedlist>
- <listitem>
- <para><link linkend="querycriteria-building">Building the criteria instance</link></para>
- <para><link linkend="querycriteria-executing">Executing the criteria instance</link></para>
- </listitem>
- </orderedlist>
<section id="querycriteria-building">
<title>Criteria query building</title>
-
<para>
Criteria queries are essentially an object graph, where each part of the graph
represents an increasing (as we navigate down this graph) more atomic part of
- query. The first step in performing a criteria query is building this graph.
+ query. The first step in performing a criteria query is building this graph.
</para>
-
<section id="querycriteria-builder">
<title>CriteriaBuilder</title>
-
<para>
- The <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename> interface is the
- first thing with which you need to become acquainted to begin using criteria queries. Its role
- is a factory for all the individual pieces of the criteria. You obtain a
- <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename> instance by calling
- the <methodname>javax.persistence.EntityManagerFactory.getCriteriaBuilder</methodname> method:
+ The
+ <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename>
+ interface is the
+ first thing with which you need to become acquainted to begin using criteria queries. Its role
+ is a factory for all the individual pieces of the criteria. You obtain a
+ <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename>
+ instance by calling
+ the
+ <methodname>javax.persistence.EntityManagerFactory.getCriteriaBuilder</methodname>
+ method:
</para>
-
<programlisting>CriteriaBuilder builder = entityManagerFactory.getCriteriaBuilder();</programlisting>
</section>
-
<section id="querycriteria-criteria">
<title>CriteriaQuery creation</title>
-
<para>
- Once you have the <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename> reference
- you can begin building the pieces of the criteria query. First, you will need a
- <interfacename>javax.persistence.criteria.CriteriaQuery</interfacename> instance.
- <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename> defines 3 methods
- for obtaining a <interfacename>javax.persistence.criteria.CriteriaQuery</interfacename>
+ Once you have the
+ <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename>
+ reference
+ you can begin building the pieces of the criteria query. First, you will need a
+ <interfacename>javax.persistence.criteria.CriteriaQuery</interfacename>
+ instance.
+ <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename>
+ defines 3 methods
+ for obtaining a
+ <interfacename>javax.persistence.criteria.CriteriaQuery</interfacename>
instance:
</para>
-
<itemizedlist>
<listitem>
<programlisting><![CDATA[CriteriaQuery<T> createQuery(Class<T>)]]></programlisting>
@@ -100,80 +110,153 @@
<programlisting><![CDATA[CriteriaQuery<Object> createQuery()]]></programlisting>
</listitem>
</itemizedlist>
-
<para>
- Each serves different purposes depending on the expected type of the query results. The type
- is "carried forward" to the <interfacename>javax.persistence.TypedQuery</interfacename> we
- create from this <interfacename>javax.persistence.criteria.CriteriaQuery</interfacename> as
- we will see <link linkend="querycriteria-executing">later</link>.
+ Each serves a different purpose depending on the expected type of the query results. The type
+ is "carried forward" to the
+ <interfacename>javax.persistence.TypedQuery</interfacename>
+ we
+ create from this
+ <interfacename>javax.persistence.criteria.CriteriaQuery</interfacename>
+ as
+ we will see later in<xref linkend="querycriteria-executing"/>later.
</para>
-
<section id="querycriteria-criteria-typed">
<title>Typed CriteriaQuery</title>
- <programlisting><![CDATA[CriteriaQuery<Person> personCriteria = builder.createQuery(Person.class);]]></programlisting>
+ <programlisting>
+ <![CDATA[CriteriaQuery<Person> personCriteria = builder.createQuery(Person.class);]]></programlisting>
<para>
Basically this is saying to create a criteria where the results of this query will be of type
- Person. Person might be an entity or it might not. The type could even be simple types like
- <classname>java.lang.Integer</classname>, <classname>java.lang.String</classname>, etc. We
- will discuss this topic in more detail in <xref linkend="querycriteria-selection"/>
+ Person. Person might be an entity or it might not. The type could even be simple types like
+ <classname>java.lang.Integer</classname>,<classname>java.lang.String</classname>, etc. We
+ will discuss this topic in more detail in
+ <xref linkend="querycriteria-selection"/>
</para>
</section>
-
<section id="querycriteria-criteria-tuple">
<title>Tuple CriteriaQuery</title>
- <programlisting><![CDATA[CriteriaQuery<Tuple> personCriteria = builder.createTupleQuery();]]></programlisting>
- <programlisting><![CDATA[CriteriaQuery<Tuple> personCriteria = builder.createQuery(Tuple.class);]]></programlisting>
+ <programlisting>
+ <![CDATA[CriteriaQuery<Tuple> personCriteria = builder.createTupleQuery();]]></programlisting>
+ <programlisting>
+ <![CDATA[CriteriaQuery<Tuple> personCriteria = builder.createQuery(Tuple.class);]]></programlisting>
<para>
- These two forms are exactly the same. Both say to create a criteria where the results of this
- query will be of type <interfacename>javax.persistence.Tuple</interfacename>. The term tuple is
+ These two forms are exactly the same. Both say to create a criteria where the results of this
+ query will be of type<interfacename>javax.persistence.Tuple</interfacename>. The term tuple is
taken from mathematics, but its intent here is simply to mean a plurality; namely we are saying
- that each query result will actually be multiple values, a projection. The
- <interfacename>javax.persistence.Tuple</interfacename> instance gives us typed access to these
- multiple result values after the query has been executed. We will discuss accessing the query
- results via a <interfacename>javax.persistence.Tuple</interfacename> in
+ that each query result will actually be multiple values, a projection. The
+ <interfacename>javax.persistence.Tuple</interfacename>
+ instance gives us typed access to these
+ multiple result values after the query has been executed. We will discuss accessing the query
+ results via a
+ <interfacename>javax.persistence.Tuple</interfacename>
+ in
<xref linkend="querycriteria-executing"/>.
</para>
</section>
-
<section id="querycriteria-criteria-untyped">
<title>Untyped CriteriaQuery</title>
- <programlisting><![CDATA[CriteriaQuery<Object> personCriteria = builder.createQuery();]]></programlisting>
- <programlisting><![CDATA[CriteriaQuery<Object> personCriteria = builder.createQuery(Object.class);]]></programlisting>
+ <programlisting>
+ <![CDATA[CriteriaQuery<Object> personCriteria = builder.createQuery();]]></programlisting>
+ <programlisting>
+ <![CDATA[CriteriaQuery<Object> personCriteria = builder.createQuery(Object.class);]]></programlisting>
<para>
- These two forms are exactly the same. Both say to create a criteria where the results of this
- query could be anything. Not generally recommended as you obviously lose the type safety.
+ These two forms are exactly the same. Both say to create a criteria where the results of this
+ query could be anything. Not generally recommended as you obviously lose the type safety.
</para>
</section>
-
</section>
-
<section id="querycriteria-from">
<title>FROM clause</title>
<blockquote>
- <attribution><biblioref linkend="JPA2" endterm="JPA2_ABBREV" /></attribution>
+ <attribution>
+ <citation>
+ <citation>JPA 2 Specification</citation>
+ </citation>
+ </attribution>
<para>
A CriteriaQuery object defines a query over one or more entity, embeddable, or basic abstract
- schema types. The root objects of the query are entities, from which the other types are reached
+ schema types. The root objects of the query are entities, from which the other types are reached
by navigation.
</para>
</blockquote>
-
+ <para>All the individual parts of the FROM clause (roots, joins, paths) implement the
+ <interfacename>javax.persistence.criteria.From</interfacename>
+ interface.
+ </para>
<section id="querycriteria-from-root">
<title>Roots</title>
- <para>
-
+ <para>Roots define the basis from which all joins, paths and attributes are available in the query. It
+ is
+ the root of the portion of your domain model you wish to query against. In a criteria query, a root
+ is always an entity. Roots are defined and added to the criteria by the overloaded
+ <methodname>from</methodname>
+ methods on<interfacename>javax.persistence.criteria.CriteriaQuery</interfacename>:
</para>
+ <programlisting><![CDATA[<X> Root<X> from(Class<X>)]]></programlisting>
+ <programlisting><![CDATA[<X> Root<X> from(EntityType<X>)]]></programlisting>
+ <programlisting><![CDATA[CriteriaQuery<Person> personCriteria = builder.createQuery( Person.class );
+// create and add the root
+person.from( Person.class );
+...]]></programlisting>
+ <para>Criteria queries may define multiple roots, the effect of which is to create a cartesean product
+ between the newly added root and the others. Here is an example matching all single men and all
+ single women:
+ </para>
+ <programlisting><![CDATA[CriteriaQuery query = builder.createQuery();
+Root<Person> men = query.from( Person.class );
+Root<Person> women = query.from( Person.class );
+Predicate menRestriction = builder.and(
+ builder.equal(
+ men.get( Person_.gender ),
+ Gender.MALE
+ ),
+ builder.equal(
+ men.get( Person_.relationshipStatus ),
+ RelationshipStatus.SINGLE
+ )
+);
+Predicate womenRestriction = builder.and(
+ builder.equal(
+ women.get( Person_.gender ),
+ Gender.FEMALE
+ ),
+ builder.equal(
+ women.get( Person_.relationshipStatus ),
+ RelationshipStatus.SINGLE
+ )
+);
+query.where(
+ builder.and( menRestriction, womenRestriction )
+);]]></programlisting>
</section>
<section id="querycriteria-from-join">
<title>Joins</title>
- <para>todo</para>
+ <para>Joins allow navigation from other
+ <interfacename>javax.persistence.criteria.From</interfacename>
+ to either association or embedded attributes. Joins are created by the numerous overloaded
+ <methodname>join</methodname>
+ methods of the
+ <interfacename>javax.persistence.criteria.From</interfacename>
+ interface:
+ </para>
+ <programlisting><![CDATA[CriteriaQuery<Person> personCriteria = builder.createQuery( Person.class );
+Root<Person> personRoot = person.from( Person.class );
+// Person.address is an embedded attribute
+Join<Person,Address> personAddress = personRoot.join( Person_.address );
+// Address.country is a ManyToOne
+Join<Address,Country> addressCountry = personAddress.join( Address_.country );
+...]]></programlisting>
+ <para>An example with collection attributes:</para>
+ <programlisting><![CDATA[CriteriaQuery<Person> personCriteria = builder.createQuery( Person.class );
+Root<Person> personRoot = person.from( Person.class );
+Join<Person,Order> orders = personRoot.join( Person_.orders );
+Join<Order,LineItem> orderLines = orders.join( Order_.lineItems );
+...]]></programlisting>
</section>
<section id="querycriteria-from-fetch">
<title>Fetches</title>
<para>todo</para>
</section>
</section>
-
<section id="querycriteria-path">
<title>Path expressions</title>
<note>
@@ -183,22 +266,17 @@
</note>
<para>todo</para>
</section>
-
<section id="querycriteria-selection">
<title>Selections</title>
<para>todo</para>
</section>
-
</section>
-
<section id="querycriteria-executing">
<title>Criteria query execution</title>
<para>todo</para>
</section>
-
<section id="querycriteria-common">
<title>Common use cases</title>
-
<section id="querycriteria-common-selectroot">
<title>Selecting the root entity</title>
<programlisting><![CDATA[// get all people with brown eyes
@@ -211,7 +289,6 @@
personCriteria.where( builder.equal( Person_.eyeColor, "brown" ) );
List<Person> people = em.createQuery( personCriteria ).getResultList();]]></programlisting>
</section>
-
<section id="querycriteria-common-selectassociation">
<title>Selecting an association</title>
<programlisting><![CDATA[// get the gender of all people with brown eyes
@@ -224,7 +301,6 @@
personCriteria.where( builder.equal( Person_.eyeColor, "brown" ) );
List<Person> people = em.createQuery( personCriteria ).getResultList();]]></programlisting>
</section>
-
<section id="querycriteria-common-selectvalue">
<title>Selecting a value</title>
<programlisting><![CDATA[// get the height of all people with brown eyes
@@ -234,7 +310,6 @@
personCriteria.where( builder.equal( Person_.eyeColor, "brown" ) );
List<Integer> heights = em.createQuery( personCriteria ).getResultList();]]></programlisting>
</section>
-
<section id="querycriteria-common-selectaggregation">
<title>Selecting an aggregated value</title>
<programlisting><![CDATA[// get the maximum height of all people with brown eyes
@@ -244,7 +319,6 @@
personCriteria.where( builder.equal( Person_.eyeColor, "brown" ) );
Integer maxHeight = em.createQuery( personCriteria ).getSingleResult();]]></programlisting>
</section>
-
<section id="querycriteria-common-selecttuple">
<title>Selecting a tuple</title>
<programlisting><![CDATA[// get the id, height and gender of all people with brown eyes
@@ -266,7 +340,6 @@
handleId( tuple.get( "id" ) );
}]]></programlisting>
</section>
-
<section id="querycriteria-common-selectconstruct">
<title>Selecting a constructed value</title>
<programlisting><![CDATA[// get the id, height and gender of all people with brown eyes
@@ -283,7 +356,6 @@
);
List<PersonHolder> people = em.createQuery( personCriteria ).getResultList();]]></programlisting>
</section>
-
<section id="querycriteria-common-param">
<title>Using parameters</title>
<programlisting><![CDATA[// get all people with brown eyes
@@ -297,5 +369,4 @@
List<Person> people = query.getResultList();]]></programlisting>
</section>
</section>
-
-</chapter>
\ No newline at end of file
+</chapter>
14 years, 2 months
Hibernate SVN: r18841 - in core/trunk/entitymanager/src/main/docbook/en: modules and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-02-19 12:08:37 -0500 (Fri, 19 Feb 2010)
New Revision: 18841
Added:
core/trunk/entitymanager/src/main/docbook/en/modules/query_criteria.xml
Modified:
core/trunk/entitymanager/src/main/docbook/en/master.xml
Log:
HHH-4936 - Document JPA criteria queries
Modified: core/trunk/entitymanager/src/main/docbook/en/master.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/master.xml 2010-02-18 19:19:45 UTC (rev 18840)
+++ core/trunk/entitymanager/src/main/docbook/en/master.xml 2010-02-19 17:08:37 UTC (rev 18841)
@@ -2,10 +2,10 @@
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
- ~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
~ indicated by the @author tags or express copyright attribution
~ statements applied by the authors. All third-party contributions are
- ~ distributed under license by Red Hat Middleware LLC.
+ ~ distributed under license by Red Hat Inc.
~
~ This copyrighted material is made available to anyone wishing to use, modify,
~ copy, or redistribute it subject to the terms and conditions of the GNU
@@ -25,7 +25,7 @@
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY versionNumber "3.4.0.GA">
<!ENTITY copyrightYear "2004">
- <!ENTITY copyrightHolder "Red Hat Middleware, LLC.">
+ <!ENTITY copyrightHolder "Red Hat Inc.">
]>
<book lang="en">
<bookinfo>
@@ -69,6 +69,24 @@
<xi:include href="modules/listeners.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="modules/batch.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="modules/query_ejbql.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="modules/query_criteria.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="modules/query_native.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <bibliography>
+ <title>References</title>
+
+ <biblioentry id="JPA2">
+ <abbrev id="JPA2_ABBREV">JPA 2 Specification</abbrev>
+ <title>JSR 317: <trademark>Java</trademark> Persistence API, Version 2.0</title>
+ <collab>Java Persistence 2.0 Expert Group</collab>
+ <copyright>
+ <year>2009</year>
+ <holder>SUN MICROSYSTEMS, INC.</holder>
+ </copyright>
+ <bibliomisc>
+ <email>jsr-317-feedback(a)sun.com</email>
+ <ulink url="http://jcp.org/en/jsr/detail?id=317"/>
+ </bibliomisc>
+ </biblioentry>
+ </bibliography>
</book>
\ No newline at end of file
Added: core/trunk/entitymanager/src/main/docbook/en/modules/query_criteria.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/query_criteria.xml (rev 0)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/query_criteria.xml 2010-02-19 17:08:37 UTC (rev 18841)
@@ -0,0 +1,301 @@
+<?xml version='1.0' encoding="UTF-8"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Inc.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+
+<chapter id="querycriteria">
+ <title>JPA Criteria Queries</title>
+
+ <note>
+ <para>
+ This chapter elaborates on the material discussed in
+ <citetitle pubwork="chapter">Chapter 6 Criteria API</citetitle> of the
+ <biblioref linkend="JPA2" endterm="JPA2_ABBREV" />.
+ </para>
+ </note>
+
+ <para>
+ Criteria queries are a programmatic, type-safe way to express a query. They are type-safe
+ in terms of using interfaces and classes to represent various structural parts of a query
+ such as the query itself, or the select clause, or an order-by, etc. They can also be
+ type-safe in terms of referencing attributes as we will see in a bit. Users of the older
+ Hibernate <interfacename>org.hibernate.Criteria</interfacename> query API will recognize
+ the general approach, though we believe the JPA API to be superior as it represents a clean
+ look at the lessons learned from that API. There are essentially 2 phases to performing
+ a criteria query:
+ </para>
+
+ <orderedlist>
+ <listitem>
+ <para><link linkend="querycriteria-building">Building the criteria instance</link></para>
+ <para><link linkend="querycriteria-executing">Executing the criteria instance</link></para>
+ </listitem>
+ </orderedlist>
+
+ <section id="querycriteria-building">
+ <title>Criteria query building</title>
+
+ <para>
+ Criteria queries are essentially an object graph, where each part of the graph
+ represents an increasing (as we navigate down this graph) more atomic part of
+ query. The first step in performing a criteria query is building this graph.
+ </para>
+
+ <section id="querycriteria-builder">
+ <title>CriteriaBuilder</title>
+
+ <para>
+ The <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename> interface is the
+ first thing with which you need to become acquainted to begin using criteria queries. Its role
+ is a factory for all the individual pieces of the criteria. You obtain a
+ <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename> instance by calling
+ the <methodname>javax.persistence.EntityManagerFactory.getCriteriaBuilder</methodname> method:
+ </para>
+
+ <programlisting>CriteriaBuilder builder = entityManagerFactory.getCriteriaBuilder();</programlisting>
+ </section>
+
+ <section id="querycriteria-criteria">
+ <title>CriteriaQuery creation</title>
+
+ <para>
+ Once you have the <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename> reference
+ you can begin building the pieces of the criteria query. First, you will need a
+ <interfacename>javax.persistence.criteria.CriteriaQuery</interfacename> instance.
+ <interfacename>javax.persistence.criteria.CriteriaBuilder</interfacename> defines 3 methods
+ for obtaining a <interfacename>javax.persistence.criteria.CriteriaQuery</interfacename>
+ instance:
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <programlisting><![CDATA[CriteriaQuery<T> createQuery(Class<T>)]]></programlisting>
+ </listitem>
+ <listitem>
+ <programlisting><![CDATA[CriteriaQuery<Tuple> createTupleQuery()]]></programlisting>
+ </listitem>
+ <listitem>
+ <programlisting><![CDATA[CriteriaQuery<Object> createQuery()]]></programlisting>
+ </listitem>
+ </itemizedlist>
+
+ <para>
+ Each serves different purposes depending on the expected type of the query results. The type
+ is "carried forward" to the <interfacename>javax.persistence.TypedQuery</interfacename> we
+ create from this <interfacename>javax.persistence.criteria.CriteriaQuery</interfacename> as
+ we will see <link linkend="querycriteria-executing">later</link>.
+ </para>
+
+ <section id="querycriteria-criteria-typed">
+ <title>Typed CriteriaQuery</title>
+ <programlisting><![CDATA[CriteriaQuery<Person> personCriteria = builder.createQuery(Person.class);]]></programlisting>
+ <para>
+ Basically this is saying to create a criteria where the results of this query will be of type
+ Person. Person might be an entity or it might not. The type could even be simple types like
+ <classname>java.lang.Integer</classname>, <classname>java.lang.String</classname>, etc. We
+ will discuss this topic in more detail in <xref linkend="querycriteria-selection"/>
+ </para>
+ </section>
+
+ <section id="querycriteria-criteria-tuple">
+ <title>Tuple CriteriaQuery</title>
+ <programlisting><![CDATA[CriteriaQuery<Tuple> personCriteria = builder.createTupleQuery();]]></programlisting>
+ <programlisting><![CDATA[CriteriaQuery<Tuple> personCriteria = builder.createQuery(Tuple.class);]]></programlisting>
+ <para>
+ These two forms are exactly the same. Both say to create a criteria where the results of this
+ query will be of type <interfacename>javax.persistence.Tuple</interfacename>. The term tuple is
+ taken from mathematics, but its intent here is simply to mean a plurality; namely we are saying
+ that each query result will actually be multiple values, a projection. The
+ <interfacename>javax.persistence.Tuple</interfacename> instance gives us typed access to these
+ multiple result values after the query has been executed. We will discuss accessing the query
+ results via a <interfacename>javax.persistence.Tuple</interfacename> in
+ <xref linkend="querycriteria-executing"/>.
+ </para>
+ </section>
+
+ <section id="querycriteria-criteria-untyped">
+ <title>Untyped CriteriaQuery</title>
+ <programlisting><![CDATA[CriteriaQuery<Object> personCriteria = builder.createQuery();]]></programlisting>
+ <programlisting><![CDATA[CriteriaQuery<Object> personCriteria = builder.createQuery(Object.class);]]></programlisting>
+ <para>
+ These two forms are exactly the same. Both say to create a criteria where the results of this
+ query could be anything. Not generally recommended as you obviously lose the type safety.
+ </para>
+ </section>
+
+ </section>
+
+ <section id="querycriteria-from">
+ <title>FROM clause</title>
+ <blockquote>
+ <attribution><biblioref linkend="JPA2" endterm="JPA2_ABBREV" /></attribution>
+ <para>
+ A CriteriaQuery object defines a query over one or more entity, embeddable, or basic abstract
+ schema types. The root objects of the query are entities, from which the other types are reached
+ by navigation.
+ </para>
+ </blockquote>
+
+ <section id="querycriteria-from-root">
+ <title>Roots</title>
+ <para>
+
+ </para>
+ </section>
+ <section id="querycriteria-from-join">
+ <title>Joins</title>
+ <para>todo</para>
+ </section>
+ <section id="querycriteria-from-fetch">
+ <title>Fetches</title>
+ <para>todo</para>
+ </section>
+ </section>
+
+ <section id="querycriteria-path">
+ <title>Path expressions</title>
+ <note>
+ <para>
+ Roots, joins and fetches are themselves paths as well
+ </para>
+ </note>
+ <para>todo</para>
+ </section>
+
+ <section id="querycriteria-selection">
+ <title>Selections</title>
+ <para>todo</para>
+ </section>
+
+ </section>
+
+ <section id="querycriteria-executing">
+ <title>Criteria query execution</title>
+ <para>todo</para>
+ </section>
+
+ <section id="querycriteria-common">
+ <title>Common use cases</title>
+
+ <section id="querycriteria-common-selectroot">
+ <title>Selecting the root entity</title>
+ <programlisting><![CDATA[// get all people with brown eyes
+CriteriaQuery<Person> personCriteria = build.createQuery( Person.class );
+Root<Person> personRoot = personCriteria.from( Person.class );
+// specifying select here is not strictly needed because 'personRoot'
+// will be the implied selection since we have only a single root;
+// but done here for explicitness
+personCriteria.select( personRoot );
+personCriteria.where( builder.equal( Person_.eyeColor, "brown" ) );
+List<Person> people = em.createQuery( personCriteria ).getResultList();]]></programlisting>
+ </section>
+
+ <section id="querycriteria-common-selectassociation">
+ <title>Selecting an association</title>
+ <programlisting><![CDATA[// get the gender of all people with brown eyes
+CriteriaQuery<Gender> personCriteria = build.createQuery( Gender.class );
+Root<Person> personRoot = personCriteria.from( Person.class );
+// specifying select here is not strictly needed because 'personRoot'
+// will be the implied selection since we have only a single root;
+// but done here for explicitness
+personCriteria.select( personRoot );
+personCriteria.where( builder.equal( Person_.eyeColor, "brown" ) );
+List<Person> people = em.createQuery( personCriteria ).getResultList();]]></programlisting>
+ </section>
+
+ <section id="querycriteria-common-selectvalue">
+ <title>Selecting a value</title>
+ <programlisting><![CDATA[// get the height of all people with brown eyes
+CriteriaQuery<Integer> personCriteria = build.createQuery( Integer.class );
+Root<Person> personRoot = personCriteria.from( Person.class );
+personCriteria.select( personRoot.get( Person.height ) );
+personCriteria.where( builder.equal( Person_.eyeColor, "brown" ) );
+List<Integer> heights = em.createQuery( personCriteria ).getResultList();]]></programlisting>
+ </section>
+
+ <section id="querycriteria-common-selectaggregation">
+ <title>Selecting an aggregated value</title>
+ <programlisting><![CDATA[// get the maximum height of all people with brown eyes
+CriteriaQuery<Integer> personCriteria = build.createQuery( Integer.class );
+Root<Person> personRoot = personCriteria.from( Person.class );
+personCriteria.select( builder.max( personRoot.get( Person.height ) ) );
+personCriteria.where( builder.equal( Person_.eyeColor, "brown" ) );
+Integer maxHeight = em.createQuery( personCriteria ).getSingleResult();]]></programlisting>
+ </section>
+
+ <section id="querycriteria-common-selecttuple">
+ <title>Selecting a tuple</title>
+ <programlisting><![CDATA[// get the id, height and gender of all people with brown eyes
+CriteriaQuery<Tuple> personCriteria = build.createTupleQuery();
+Root<Person> personRoot = personCriteria.from( Person.class );
+Path<Long> idPath = personRoot.get( Person_.id );
+idPath.setAlias( "id" );
+Path<Integer> heightPath = personRoot.get( Person_.height );
+Path<Gender> genderPath = personRoot.get( Person_.gender );
+personCriteria.multiselect( idPath, heightPath, genderPath );
+personCriteria.where( builder.equal( Person_.eyeColor, "brown" ) );
+List<Tuple> tuples = em.createQuery( personCriteria ).getResultList();
+for ( Tuple tuple : tuples ) {
+ // the id value, for example, can be accessed by expression...
+ handleId( tuple.get( idPath ) );
+ // or by position...
+ handleId( tuple.get( 0 ) );
+ // or by the explicit alias we gave it...
+ handleId( tuple.get( "id" ) );
+}]]></programlisting>
+ </section>
+
+ <section id="querycriteria-common-selectconstruct">
+ <title>Selecting a constructed value</title>
+ <programlisting><![CDATA[// get the id, height and gender of all people with brown eyes
+// like we did before, but this time wrap them in a "holder"
+CriteriaQuery<PersonHolder> personCriteria = build.createQuery( PersonHolder.class );
+Root<Person> personRoot = personCriteria.from( Person.class );
+personCriteria.select(
+ builder.construct(
+ PersonHolder.class,
+ personRoot.get( Person_.id ),
+ personRoot.get( Person_.height ),
+ personRoot.get( Person_.gender )
+ )
+);
+List<PersonHolder> people = em.createQuery( personCriteria ).getResultList();]]></programlisting>
+ </section>
+
+ <section id="querycriteria-common-param">
+ <title>Using parameters</title>
+ <programlisting><![CDATA[// get all people with brown eyes
+CriteriaQuery<Person> personCriteria = build.createQuery( Person.class );
+Root<Person> personRoot = personCriteria.from( Person.class );
+personCriteria.select( personRoot );
+ParameterExpression<String> eyeColorParam = builder.parameter( String.class );
+personCriteria.where( builder.equal( Person_.eyeColor, eyeColorParam ) );
+TypedQuery<Person> query = em.createQuery( personCriteria );
+query.setParameter( eyeColorParam, "brown" );
+List<Person> people = query.getResultList();]]></programlisting>
+ </section>
+ </section>
+
+</chapter>
\ No newline at end of file
14 years, 2 months
Hibernate SVN: r18840 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-02-18 14:19:45 -0500 (Thu, 18 Feb 2010)
New Revision: 18840
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
Log:
HHH-4934 - Improve logging in MetadataContext and AttributeFactory
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-02-18 17:00:47 UTC (rev 18839)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-02-18 19:19:45 UTC (rev 18840)
@@ -36,6 +36,9 @@
import javax.persistence.metamodel.Type;
import javax.persistence.metamodel.IdentifiableType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.hibernate.EntityMode;
import org.hibernate.type.EmbeddedComponentType;
import org.hibernate.type.ComponentType;
@@ -61,6 +64,8 @@
* @author Emmanuel Bernard
*/
public class AttributeFactory {
+ private static final Logger log = LoggerFactory.getLogger( AttributeFactory.class );
+
private final MetadataContext context;
public AttributeFactory(MetadataContext context) {
@@ -78,6 +83,7 @@
*/
@SuppressWarnings({ "unchecked" })
public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property) {
+ log.trace( "Building attribute [{}.{}]", ownerType.getJavaType().getName(), property.getName() );
//a back ref is a virtual property created by Hibernate, let's hide it from the JPA model.
if ( property.isBackRef() ) return null;
final AttributeContext<X> attributeContext = wrap( ownerType, property );
@@ -128,6 +134,7 @@
*/
@SuppressWarnings({ "unchecked" })
public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(AbstractIdentifiableType<X> ownerType, Property property) {
+ log.trace( "Building identifier attribute [{}.{}]", ownerType.getJavaType().getName(), property.getName() );
final AttributeContext<X> attributeContext = wrap( ownerType, property );
final SingularAttributeMetadata<X,Y> attributeMetadata =
(SingularAttributeMetadata<X, Y>) determineAttributeMetadata( attributeContext, IDENTIFIER_MEMBER_RESOLVER );
@@ -153,6 +160,7 @@
*/
@SuppressWarnings({ "unchecked" })
public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(AbstractIdentifiableType<X> ownerType, Property property) {
+ log.trace( "Building version attribute [{}.{}]", ownerType.getJavaType().getName(), property.getName() );
final AttributeContext<X> attributeContext = wrap( ownerType, property );
final SingularAttributeMetadata<X,Y> attributeMetadata =
(SingularAttributeMetadata<X, Y>) determineAttributeMetadata( attributeContext, VERSION_MEMBER_RESOLVER );
@@ -429,14 +437,14 @@
private <X,Y> AttributeMetadata<X,Y> determineAttributeMetadata(
AttributeContext<X> attributeContext,
MemberResolver memberResolver) {
+ log.trace( "Starting attribute metadata determination [{}]", attributeContext.getPropertyMapping().getName() );
final Member member = memberResolver.resolveMember( attributeContext );
- // TODO (steve->emmanuel) not so sure this is true any longer...
- // FIXME the logical level for *To* is different from the Hibernate physical model.
- // ie a @ManyToOne @AssocTable is a many-to-many for hibernate
- // and a @OneToMany @AssocTable is a many-to-many for hibernate
- // FIXME so basically Attribute.PersistentAttributeType is crap at the moment
+ log.trace( " Determined member [{}]", member );
+
final Value value = attributeContext.getPropertyMapping().getValue();
final org.hibernate.type.Type type = value.getType();
+ log.trace( " determined type [name={}, class={}]", type.getName(), type.getClass().getName() );
+
if ( type.isAnyType() ) {
throw new UnsupportedOperationException( "any not supported yet" );
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2010-02-18 17:00:47 UTC (rev 18839)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2010-02-18 19:19:45 UTC (rev 18840)
@@ -21,29 +21,30 @@
*/
package org.hibernate.ejb.metamodel;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.lang.reflect.Field;
import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.IdentifiableType;
import javax.persistence.metamodel.SingularAttribute;
-import javax.persistence.metamodel.IdentifiableType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.hibernate.annotations.common.AssertionFailure;
+import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.annotations.common.AssertionFailure;
/**
* Defines a context for storing information during the building of the {@link MetamodelImpl}.
@@ -52,8 +53,8 @@
* cross-references into the built metamodel classes.
* <p/>
* At the end of the day, clients are interested in the {@link #getEntityTypeMap} and {@link #getEmbeddableTypeMap}
- * results, which represent all the registered {@link #registerEntityType entities} and
- * {@link #registerEmbeddedableType embeddabled} respectively.
+ * results, which represent all the registered {@linkplain #registerEntityType entities} and
+ * {@linkplain #registerEmbeddedableType embeddables} respectively.
*
* @author Steve Ebersole
* @author Emmanuel Bernard
@@ -94,9 +95,9 @@
}
/**
- * Retrieves the {@link Class java type} to {@link EntityType} map.
+ * Retrieves the {@linkplain Class java type} to {@link EntityTypeImpl} map.
*
- * @return The {@link Class java type} to {@link EntityType} map.
+ * @return The {@linkplain Class java type} to {@link EntityTypeImpl} map.
*/
public Map<Class<?>, EntityTypeImpl<?>> getEntityTypeMap() {
return Collections.unmodifiableMap( entityTypes );
@@ -159,49 +160,62 @@
@SuppressWarnings({ "unchecked" })
public void wrapUp() {
+ log.trace( "Wrapping up metadata context..." );
//we need to process types from superclasses to subclasses
for (Object mapping : orderedMappings) {
if ( PersistentClass.class.isAssignableFrom( mapping.getClass() ) ) {
@SuppressWarnings( "unchecked" )
final PersistentClass safeMapping = (PersistentClass) mapping;
- final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get( safeMapping );
- applyIdMetadata( safeMapping, jpa2Mapping );
- applyVersionAttribute( safeMapping, jpa2Mapping );
- Iterator<Property> properties = ( Iterator<Property> ) safeMapping.getDeclaredPropertyIterator();
- while ( properties.hasNext() ) {
- final Property property = properties.next();
- if ( property.getValue() == safeMapping.getIdentifierMapper() ) {
- // property represents special handling for id-class mappings but we have already
- // accounted for the embedded property mappings in #applyIdMetadata &&
- // #buildIdClassAttributes
- continue;
+ log.trace( "Starting entity [{}]", safeMapping.getEntityName() );
+ try {
+ final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get( safeMapping );
+ applyIdMetadata( safeMapping, jpa2Mapping );
+ applyVersionAttribute( safeMapping, jpa2Mapping );
+ Iterator<Property> properties = ( Iterator<Property> ) safeMapping.getDeclaredPropertyIterator();
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ if ( property.getValue() == safeMapping.getIdentifierMapper() ) {
+ // property represents special handling for id-class mappings but we have already
+ // accounted for the embedded property mappings in #applyIdMetadata &&
+ // #buildIdClassAttributes
+ continue;
+ }
+ final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
+ if ( attribute != null ) {
+ jpa2Mapping.getBuilder().addAttribute( attribute );
+ }
}
- final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
- if ( attribute != null ) {
- jpa2Mapping.getBuilder().addAttribute( attribute );
- }
+ jpa2Mapping.lock();
+ populateStaticMetamodel( jpa2Mapping );
}
- jpa2Mapping.lock();
- populateStaticMetamodel( jpa2Mapping );
+ finally {
+ log.trace( "Completed entity [{}]", safeMapping.getEntityName() );
+ }
}
else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
@SuppressWarnings( "unchecked" )
final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
- final MappedSuperclassTypeImpl<?> jpa2Mapping = mappedSuperclassByMappedSuperclassMapping.get(
- safeMapping
- );
- applyIdMetadata( safeMapping, jpa2Mapping );
- applyVersionAttribute( safeMapping, jpa2Mapping );
- Iterator<Property> properties = ( Iterator<Property> ) safeMapping.getDeclaredPropertyIterator();
- while ( properties.hasNext() ) {
- final Property property = properties.next();
- final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
- if ( attribute != null ) {
- jpa2Mapping.getBuilder().addAttribute( attribute );
+ log.trace( "Starting mapped superclass [{}]", safeMapping.getMappedClass().getName() );
+ try {
+ final MappedSuperclassTypeImpl<?> jpa2Mapping = mappedSuperclassByMappedSuperclassMapping.get(
+ safeMapping
+ );
+ applyIdMetadata( safeMapping, jpa2Mapping );
+ applyVersionAttribute( safeMapping, jpa2Mapping );
+ Iterator<Property> properties = ( Iterator<Property> ) safeMapping.getDeclaredPropertyIterator();
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
+ if ( attribute != null ) {
+ jpa2Mapping.getBuilder().addAttribute( attribute );
+ }
}
+ jpa2Mapping.lock();
+ populateStaticMetamodel( jpa2Mapping );
}
- jpa2Mapping.lock();
- populateStaticMetamodel( jpa2Mapping );
+ finally {
+ log.trace( "Completed mapped superclass [{}]", safeMapping.getMappedClass().getName() );
+ }
}
else {
throw new AssertionFailure( "Unexpected mapping type: " + mapping.getClass() );
@@ -296,6 +310,7 @@
private <X> Set<SingularAttribute<? super X, ?>> buildIdClassAttributes(
MappedSuperclassTypeImpl<X> jpaMappingType,
MappedSuperclass mappingType) {
+ log.trace( "Building old-school composite identifier [{}]", mappingType.getMappedClass().getName() );
Set<SingularAttribute<? super X, ?>> attributes = new HashSet<SingularAttribute<? super X, ?>>();
@SuppressWarnings( "unchecked" )
Iterator<Property> properties = mappingType.getIdentifierMapper().getPropertyIterator();
14 years, 2 months
Hibernate SVN: r18839 - in core/trunk/entitymanager/src: main/java/org/hibernate/ejb/criteria/predicate and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-02-18 12:00:47 -0500 (Thu, 18 Feb 2010)
New Revision: 18839
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanStaticAssertionPredicate.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
Log:
HHH-4583 - Incorrect handling of empty conjunction and disjunction
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java 2010-02-18 16:19:05 UTC (rev 18838)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaBuilderImpl.java 2010-02-18 17:00:47 UTC (rev 18839)
@@ -73,6 +73,7 @@
import org.hibernate.ejb.criteria.path.PluralAttributePath;
import org.hibernate.ejb.criteria.predicate.BooleanAssertionPredicate;
import org.hibernate.ejb.criteria.predicate.BooleanExpressionPredicate;
+import org.hibernate.ejb.criteria.predicate.BooleanStaticAssertionPredicate;
import org.hibernate.ejb.criteria.predicate.NullnessPredicate;
import org.hibernate.ejb.criteria.predicate.CompoundPredicate;
import org.hibernate.ejb.criteria.predicate.ComparisonPredicate;
@@ -316,9 +317,11 @@
public Predicate isTrue(Expression<Boolean> expression) {
if ( CompoundPredicate.class.isInstance( expression ) ) {
final CompoundPredicate predicate = (CompoundPredicate) expression;
- if ( predicate.getOperator() == Predicate.BooleanOperator.OR
- && predicate.getExpressions().size() == 0 ) {
- predicate.not();
+ if ( predicate.getExpressions().size() == 0 ) {
+ return new BooleanStaticAssertionPredicate(
+ this,
+ predicate.getOperator() == Predicate.BooleanOperator.AND
+ );
}
return predicate;
}
@@ -334,13 +337,13 @@
public Predicate isFalse(Expression<Boolean> expression) {
if ( CompoundPredicate.class.isInstance( expression ) ) {
final CompoundPredicate predicate = (CompoundPredicate) expression;
- if ( predicate.getOperator() == Predicate.BooleanOperator.OR
- && predicate.getExpressions().size() == 0 ) {
- // nothing to do
+ if ( predicate.getExpressions().size() == 0 ) {
+ return new BooleanStaticAssertionPredicate(
+ this,
+ predicate.getOperator() == Predicate.BooleanOperator.OR
+ );
}
- else {
- predicate.not();
- }
+ predicate.not();
return predicate;
}
else if ( Predicate.class.isInstance( expression ) ) {
@@ -351,7 +354,7 @@
return new BooleanAssertionPredicate( this, expression, Boolean.FALSE );
}
- /**
+ /**s
* {@inheritDoc}
*/
public Predicate isNull(Expression<?> x) {
Copied: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanStaticAssertionPredicate.java (from rev 18810, core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanAssertionPredicate.java)
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanStaticAssertionPredicate.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanStaticAssertionPredicate.java 2010-02-18 17:00:47 UTC (rev 18839)
@@ -0,0 +1,81 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.criteria.predicate;
+
+import java.io.Serializable;
+
+import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.ParameterRegistry;
+
+/**
+ * Predicate used to assert a static boolean condition.
+ *
+ * @author Steve Ebersole
+ */
+public class BooleanStaticAssertionPredicate
+ extends AbstractSimplePredicate
+ implements Serializable {
+ private final Boolean assertedValue;
+
+ public BooleanStaticAssertionPredicate(
+ CriteriaBuilderImpl criteriaBuilder,
+ Boolean assertedValue) {
+ super( criteriaBuilder );
+ this.assertedValue = assertedValue;
+ }
+
+ public Boolean getAssertedValue() {
+ return assertedValue;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void registerParameters(ParameterRegistry registry) {
+ // nada
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ boolean isTrue = getAssertedValue();
+ if ( isNegated() ) {
+ isTrue = !isTrue;
+ }
+
+ return isTrue
+ ? "1=1"
+ : "0=1";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
+
+}
\ No newline at end of file
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-02-18 16:19:05 UTC (rev 18838)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/criteria/basic/ExpressionsTest.java 2010-02-18 17:00:47 UTC (rev 18839)
@@ -82,6 +82,66 @@
em.close();
}
+ public void testEmptyConjunctionIsTrue() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ criteria.from( Product.class );
+ criteria.where( builder.isTrue( builder.and() ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 1, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testEmptyConjunctionIsFalse() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ criteria.from( Product.class );
+ criteria.where( builder.isFalse( builder.and() ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 0, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testEmptyDisjunction() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ criteria.from( Product.class );
+ criteria.where( builder.disjunction() );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 0, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testEmptyDisjunctionIsTrue() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ criteria.from( Product.class );
+ criteria.where( builder.isTrue( builder.disjunction() ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 0, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
+ public void testEmptyDisjunctionIsFalse() {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ CriteriaQuery<Product> criteria = builder.createQuery( Product.class );
+ criteria.from( Product.class );
+ criteria.where( builder.isFalse( builder.disjunction() ) );
+ List<Product> result = em.createQuery( criteria ).getResultList();
+ assertEquals( 1, result.size() );
+ em.getTransaction().commit();
+ em.close();
+ }
+
public void testDiff() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
14 years, 2 months
Hibernate SVN: r18838 - core/trunk/annotations/src/main/docbook/en/modules.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-02-18 11:19:05 -0500 (Thu, 18 Feb 2010)
New Revision: 18838
Modified:
core/trunk/annotations/src/main/docbook/en/modules/entity.xml
Log:
HHH-4933 fix syntax inconsistencies in XML
Modified: core/trunk/annotations/src/main/docbook/en/modules/entity.xml
===================================================================
--- core/trunk/annotations/src/main/docbook/en/modules/entity.xml 2010-02-18 15:33:57 UTC (rev 18837)
+++ core/trunk/annotations/src/main/docbook/en/modules/entity.xml 2010-02-18 16:19:05 UTC (rev 18838)
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
- ~
- ~ Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ ~ Copyright (c) 2008, Red Hat Inc. or third-party contributors as
~ indicated by the @author tags or express copyright attribution
~ statements applied by the authors. All third-party contributions are
~ distributed under license by Red Hat Middleware LLC.
@@ -27,46 +26,45 @@
<chapter id="entity">
<title>Entity Beans</title>
- <sect1 id="entity-overview" revision="2">
+ <section id="entity-overview" revision="2">
<title>Intro</title>
- <para>This section covers Java Persistence 2.0 mapping annotations as well
- as Hibernate-specific extensions.</para>
- </sect1>
+ <para>This section explains how to describe persistence mappings using
+ Java Persistence 2.0 annotations as well as Hibernate-specific annotation
+ extensions.</para>
+ </section>
- <sect1 id="entity-mapping" revision="2">
- <title>Mapping with EJB3/JPA Annotations</title>
+ <section id="entity-mapping" revision="2">
+ <title>Mapping with JPA (Java Persistence Annotations)</title>
- <para>EJB3 entities are plain POJOs. Actually they represent the exact
- same concept as the Hibernate persistent entities. Their mappings are
- defined through JDK 5.0 annotations (an XML descriptor syntax for
- overriding is defined in the EJB3 specification). Annotations can be split
- in two categories, the logical mapping annotations (allowing you to
- describe the object model, the class associations, etc.) and the physical
- mapping annotations (describing the physical schema, tables, columns,
- indexes, etc). We will mix annotations from both categories in the
- following code examples.</para>
+ <para>JPA entities are plain POJOs. Actually, they are Hibernate
+ persistent entities. Their mappings are defined through JDK 5.0
+ annotations instead of hbm.xml files. A JPA 2 XML descriptor syntax for
+ overriding is defined as well). Annotations can be split in two
+ categories, the logical mapping annotations (describing the object model,
+ the association between two entities etc.) and the physical mapping
+ annotations (describing the physical schema, tables, columns, indexes,
+ etc). We will mix annotations from both categories in the following code
+ examples.</para>
- <para>EJB3 annotations are in the <literal>javax.persistence.*</literal>
- package. Most JDK 5 compliant IDE (like Eclipse, IntelliJ IDEA and
- Netbeans) can autocomplete annotation interfaces and attributes for you
- (even without a specific "EJB3" module, since EJB3 annotations are plain
- JDK 5 annotations).</para>
+ <para>JPA annotations are in the <literal>javax.persistence.*</literal>
+ package. You favorite IDE can auto-complete annotations and their
+ attributes for you (even without a specific "JPA" module, since JPA
+ annotations are plain JDK 5 annotations).</para>
- <para>For more and runnable concrete examples read the JBoss EJB 3.0
- tutorial or review the Hibernate Annotations test suite. Most of the unit
- tests have been designed to represent a concrete example and be a
- inspiration source.</para>
+ <para>A good an complete set of working examples can be found in the
+ Hibernate Annotations test suite itself: most of the unit tests have been
+ designed to represent a concrete example and be a source of inspiration
+ for you. You can get the test suite sources in the distribution.</para>
- <sect2 id="entity-mapping-entity">
- <title>Declaring an entity bean</title>
+ <section id="entity-mapping-entity">
+ <title>Marking a POJO as persistent entity</title>
- <para>Every bound persistent POJO class is an entity bean and is
- declared using the <literal>@Entity</literal> annotation (at the class
+ <para>Every persistent POJO class is an entity bean and is declared
+ using the <literal>@Entity</literal> annotation (at the class
level):</para>
- <programlisting>
-@Entity
+ <programlisting>@Entity
public class Flight implements Serializable {
Long id;
@@ -74,28 +72,30 @@
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
-}
- </programlisting>
+} </programlisting>
<para><literal>@Entity</literal> declares the class as an entity bean
(i.e. a persistent POJO class), <literal>@Id</literal> declares the
identifier property of this entity bean. The other mapping declarations
- are implicit. This configuration by exception concept is central to the
- new EJB3 specification and a major improvement. The class Flight is
- mapped to the Flight table, using the column id as its primary key
- column.</para>
+ are implicit. The class Flight is mapped to the Flight table, using the
+ column id as its primary key column.</para>
+ <note>
+ <para>The concept of configuration by exception is central to the JPA
+ specification.</para>
+ </note>
+
<para>Depending on whether you annotate fields or methods, the access
type used by Hibernate will be <literal>field</literal> or
<literal>property</literal>. The EJB3 spec requires that you declare
annotations on the element type that will be accessed, i.e. the getter
method if you use <literal>property</literal> access, the field if you
- use <literal>field</literal> access. Mixing EJB3 annotations in both
- fields and methods should be avoided. Hibernate will guess the access
- type from the position of <literal>@Id</literal> or
+ use <literal>field</literal> access. Mixing annotations in both fields
+ and methods should be avoided. Hibernate will guess the access type from
+ the position of <literal>@Id</literal> or
<literal>@EmbeddedId</literal>.</para>
- <sect3>
+ <section>
<title>Defining the table</title>
<para><literal>@Table</literal> is set at the class level; it allows
@@ -103,19 +103,20 @@
bean mapping. If no <literal>@Table</literal> is defined the default
values are used: the unqualified class name of the entity.</para>
- <programlisting>
-@Entity
+ <programlisting>@Entity
@Table(name="tbl_sky")
public class Sky implements Serializable {
-...
- </programlisting>
+ ...
+} </programlisting>
- <para>The <literal>@Table</literal> element also contains a
- <literal>schema</literal> and a <literal>catalog</literal> attributes,
+ <para>The <literal>@Table</literal> element contains a
+ <literal>schema</literal> and <literal>catalog</literal> attributes,
if they need to be defined. You can also define unique constraints to
the table using the <literal>@UniqueConstraint</literal> annotation in
conjunction with <literal>@Table</literal> (for a unique constraint
- bound to a single column, refer to <literal>@Column</literal>).</para>
+ bound to a single column, it is recommended to use the
+ <code>@Column.unique</code> approach (refer to
+ <literal>@Column</literal> for more information).</para>
<programlisting>@Table(name="tbl_sky",
<emphasis role="bold">uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})}</emphasis>
@@ -126,21 +127,23 @@
column names.</para>
<remark>The logical column name is defined by the Hibernate
- NamingStrategy implementation. The default EJB3 naming strategy use
- the physical column name as the logical column name. Note that this
- may be different than the property name (if the column name is
- explicit). Unless you override the NamingStrategy, you shouldn't worry
- about that.</remark>
- </sect3>
+ <classname>NamingStrategy</classname> implementation. The default JPA
+ naming strategy uses the physical column name as the logical column
+ name but it could be different if for example you append fld_ to all
+ your columns using a custom <classname>NamingStrategy</classname>
+ implementation. Note that the logical column name is not necessarily
+ equals to the property name esp when the column name is explicitly
+ set. Unless you override the <classname>NamingStrategy</classname>,
+ you shouldn't worry about that.</remark>
+ </section>
- <sect3 id="entity-mapping-entity-version" revision="1">
+ <section id="entity-mapping-entity-version" revision="1">
<title>Versioning for optimistic locking</title>
<para>You can add optimistic locking capability to an entity bean
using the <literal>@Version</literal> annotation:</para>
- <programlisting>
-@Entity
+ <programlisting>@Entity
public class Flight implements Serializable {
...
@Version
@@ -154,29 +157,31 @@
otherwise see with the last-commit-wins strategy).</para>
<para>The version column may be a numeric (the recommended solution)
- or a timestamp as per the EJB3 spec. Hibernate support any kind of
- type provided that you define and implement the appropriate
+ or a timestamp. Hibernate supports any kind of type provided that you
+ define and implement the appropriate
<classname>UserVersionType</classname>.</para>
<para>The application must not alter the version number set up by
Hibernate in any way. To artificially increase the version number,
check in Hibernate Entity Manager's reference documentation
- <literal>LockMode.WRITE</literal></para>
- </sect3>
- </sect2>
+ <literal>LockModeType.OPTIMISTIC_FORCE_INCREMENT</literal> or
+ <literal>LockModeType.PESSIMISTIC_FORCE_INCREMENT</literal>.</para>
+ </section>
+ </section>
- <sect2 id="entity-mapping-property" revision="1">
+ <section id="entity-mapping-property" revision="1">
<title>Mapping simple properties</title>
- <sect3>
+ <section>
<title>Declaring basic property mappings</title>
- <para>Every non static non transient property (field or method) of an
- entity bean is considered persistent, unless you annotate it as
- <literal>@Transient</literal>. Not having an annotation for your
- property is equivalent to the appropriate <literal>@Basic</literal>
- annotation. The <literal>@Basic</literal> annotation allows you to
- declare the fetching strategy for a property:</para>
+ <para>Every non static non transient property (field or method
+ depending on the access type) of an entity bean is considered
+ persistent, unless you annotate it as <literal>@Transient</literal>.
+ Not having an annotation for your property is equivalent to the
+ appropriate <literal>@Basic</literal> annotation. The
+ <literal>@Basic</literal> annotation allows you to declare the
+ fetching strategy for a property:</para>
<programlisting>public transient int counter; //transient property
@@ -212,30 +217,32 @@
<note>
<para>To enable property level lazy fetching, your classes have to
- be instrumented: bytecode is added to the original one to enable
+ be instrumented: bytecode is added to the original class to enable
such feature, please refer to the Hibernate reference documentation.
If your classes are not instrumented, property level lazy loading is
silently ignored.</para>
</note>
<para>The recommended alternative is to use the projection capability
- of EJB-QL or Criteria queries.</para>
+ of JP-QL (Java Persistence Query Language) or Criteria queries.</para>
- <para>EJB3 support property mapping of all basic types supported by
+ <para>JPA support property mapping of all basic types supported by
Hibernate (all basic Java types , their respective wrappers and
serializable classes). Hibernate Annotations support out of the box
- Enum type mapping either into a ordinal column (saving the enum
+ enum type mapping either into a ordinal column (saving the enum
ordinal) or a string based column (saving the enum string
representation): the persistence representation, defaulted to ordinal,
- can be overriden through the <literal>@Enumerated</literal> annotation
- as shown in the <literal>note</literal> property example.</para>
+ can be overridden through the <literal>@Enumerated</literal>
+ annotation as shown in the <literal>note</literal> property
+ example.</para>
- <para>In core Java APIs, the temporal precision is not defined. When
- dealing with temporal data you might want to describe the expected
- precision in database. Temporal data can have <literal>DATE</literal>,
- <literal>TIME</literal>, or <literal>TIMESTAMP</literal> precision (ie
- the actual date, only the time, or both). Use the
- <literal>@Temporal</literal> annotation to fine tune that.</para>
+ <para>In plain Java APIs, the temporal precision of time is not
+ defined. When dealing with temporal data you might want to describe
+ the expected precision in database. Temporal data can have
+ <literal>DATE</literal>, <literal>TIME</literal>, or
+ <literal>TIMESTAMP</literal> precision (ie the actual date, only the
+ time, or both). Use the <literal>@Temporal</literal> annotation to
+ fine tune that.</para>
<para><literal>@Lob</literal> indicates that the property should be
persisted in a Blob or a Clob depending on the property type:
@@ -263,9 +270,15 @@
and if the property is not annotated with <literal>@Lob</literal>,
then the Hibernate <literal>serializable</literal> type is
used.</para>
- </sect3>
+ </section>
- <sect3 id="entity-mapping-property-column" revision="1">
+ <section>
+ <title></title>
+
+ <para></para>
+ </section>
+
+ <section id="entity-mapping-property-column" revision="1">
<title>Declaring column attributes</title>
<para>The column(s) used for a property mapping can be defined using
@@ -409,9 +422,9 @@
</callout>
</calloutlist>
</programlistingco>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Embedded objects (aka components)</title>
<para>It is possible to declare an embedded component inside an entity
@@ -512,9 +525,9 @@
<classname>DefaultComponentSafeNamingStrategy</classname> is a small
improvement over the default EJB3NamingStrategy that allows embedded
objects to be defaulted even if used twice in the same entity.</para>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Non-annotated property defaults</title>
<para>If a property is not annotated, the following rules
@@ -522,26 +535,32 @@
<itemizedlist>
<listitem>
- If the property is of a single type, it is mapped as @Basic
+ <para>If the property is of a single type, it is mapped as
+ @Basic</para>
</listitem>
<listitem>
- Otherwise, if the type of the property is annotated as @Embeddable, it is mapped as @Embedded
+ <para>Otherwise, if the type of the property is annotated as
+ @Embeddable, it is mapped as @Embedded</para>
</listitem>
<listitem>
- Otherwise, if the type of the property is Serializable, it is mapped as @Basic in a column holding the object in its serialized version
+ <para>Otherwise, if the type of the property is Serializable, it
+ is mapped as @Basic in a column holding the object in its
+ serialized version</para>
</listitem>
<listitem>
- Otherwise, if the type of the property is java.sql.Clob or java.sql.Blob, it is mapped as @Lob with the appropriate LobType
+ <para>Otherwise, if the type of the property is java.sql.Clob or
+ java.sql.Blob, it is mapped as @Lob with the appropriate
+ LobType</para>
</listitem>
</itemizedlist>
- </sect3>
- </sect2>
+ </section>
+ </section>
- <sect2 id="entity-mapping-identifier" label=""
- xreflabel="Mapping identifier properties">
+ <section id="entity-mapping-identifier" label=""
+ xreflabel="Mapping identifier properties">
<title>Mapping identifier properties</title>
<para>The <literal>@Id</literal> annotation lets you define which
@@ -552,19 +571,20 @@
<itemizedlist>
<listitem>
- AUTO - either identity column, sequence or table depending on the underlying DB
+ <para>AUTO - either identity column, sequence or table depending on
+ the underlying DB</para>
</listitem>
<listitem>
- TABLE - table holding the id
+ <para>TABLE - table holding the id</para>
</listitem>
<listitem>
- IDENTITY - identity column
+ <para>IDENTITY - identity column</para>
</listitem>
<listitem>
- SEQUENCE - sequence
+ <para>SEQUENCE - sequence</para>
</listitem>
</itemizedlist>
@@ -683,15 +703,17 @@
<itemizedlist>
<listitem>
- annotate the component property as @Id and make the component class @Embeddable
+ <para>annotate the component property as @Id and make the component
+ class @Embeddable</para>
</listitem>
<listitem>
- annotate the component property as @EmbeddedId
+ <para>annotate the component property as @EmbeddedId</para>
</listitem>
<listitem>
- annotate the class as @IdClass and annotate each property of the entity involved in the primary key with @Id
+ <para>annotate the class as @IdClass and annotate each property of
+ the entity involved in the primary key with @Id</para>
</listitem>
</itemizedlist>
@@ -781,24 +803,27 @@
public Presenter presenter;
}
</programlisting>
- </sect2>
+ </section>
- <sect2>
+ <section>
<title>Mapping inheritance</title>
<para>EJB3 supports the three types of inheritance:</para>
<itemizedlist>
<listitem>
- Table per Class Strategy: the <union-class> element in Hibernate
+ <para>Table per Class Strategy: the <union-class> element in
+ Hibernate</para>
</listitem>
<listitem>
- Single Table per Class Hierarchy Strategy: the <subclass> element in Hibernate
+ <para>Single Table per Class Hierarchy Strategy: the
+ <subclass> element in Hibernate</para>
</listitem>
<listitem>
- Joined Subclass Strategy: the <joined-subclass> element in Hibernate
+ <para>Joined Subclass Strategy: the <joined-subclass> element
+ in Hibernate</para>
</listitem>
</itemizedlist>
@@ -810,7 +835,7 @@
<para>Annotating interfaces is currently not supported.</para>
</note>
- <sect3>
+ <section>
<title>Table per class</title>
<para>This strategy has many drawbacks (esp. with polymorphic queries
@@ -832,9 +857,9 @@
shared across several tables. Consequently, when using this strategy,
you should not use <literal>AUTO </literal>nor
<literal>IDENTITY</literal>.</para>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Single table per class hierarchy</title>
<para>All properties of all super- and subclasses are mapped into the
@@ -874,9 +899,9 @@
<para><literal>@Inheritance</literal> and
<literal>@DiscriminatorColumn</literal> should only be defined at the
top of the entity hierarchy.</para>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Joined subclasses</title>
<para>The<literal> @PrimaryKeyJoinColumn</literal> and
@@ -902,9 +927,9 @@
<literal>AmericaCupClass</literal> table is joined with
<literal>Boat</literal> using the join condition <code>Boat.id =
AmericaCupClass.BOAT_ID</code>.</para>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Inherit properties from superclasses</title>
<para>This is sometimes useful to share common properties through a
@@ -1005,13 +1030,13 @@
<literal>@Entity</literal> classes,
<literal>@MappedSuperclass</literal> classes and properties pointing
to an <literal>@Embeddable</literal> object.</para>
- </sect3>
- </sect2>
+ </section>
+ </section>
- <sect2 id="entity-mapping-association">
+ <section id="entity-mapping-association">
<title>Mapping entity bean associations/relationships</title>
- <sect3>
+ <section>
<title>One-to-one</title>
<para>You can associate entity beans through a one-to-one relationship
@@ -1143,9 +1168,9 @@
<para>You must declare the join table name and the join columns
explicitly in such a mapping.</para>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Many-to-one</title>
<para>Many-to-one associations are declared at the property level with
@@ -1216,13 +1241,13 @@
...
}
</programlisting>
- </sect3>
+ </section>
- <sect3 id="entity-mapping-association-collections" revision="1">
+ <section id="entity-mapping-association-collections" revision="1">
<title>Collections</title>
- <sect4 id="entity-mapping-association-collections-overview"
- revision="1">
+ <section id="entity-mapping-association-collections-overview"
+ revision="1">
<title>Overview</title>
<para>You can map <classname>Collection</classname>,
@@ -1390,17 +1415,17 @@
<para>Unless the collection is a generic, you will have to define
<literal>targetEntity</literal>. This is a annotation attribute that
take the target entity class as a value.</para>
- </sect4>
+ </section>
- <sect4 id="entity-mapping-association-collection-onetomany"
- revision="2">
+ <section id="entity-mapping-association-collection-onetomany"
+ revision="2">
<title>One-to-many</title>
<para>One-to-many associations are declared at the property level
with the annotation <literal>@OneToMany</literal>. One to many
associations may be bidirectional.</para>
- <sect5>
+ <section>
<title>Bidirectional</title>
<para>Since many to one are (almost) always the owner side of a
@@ -1451,9 +1476,9 @@
public Troop getTroop() {
...
}</programlisting>
- </sect5>
+ </section>
- <sect5>
+ <section>
<title>Unidirectional</title>
<para>A unidirectional one to many using a foreign key column in
@@ -1481,9 +1506,9 @@
<para><literal>Customer</literal> describes a unidirectional
relationship with <literal>Ticket</literal> using the join column
<literal>CUST_ID</literal>.</para>
- </sect5>
+ </section>
- <sect5>
+ <section>
<title>Unidirectional with join table</title>
<para>A unidirectional one to many with join table is much
@@ -1516,10 +1541,10 @@
(<literal>joinColumns</literal>) and a foreign key
<literal>monkey_id</literal> to <literal>Monkey</literal>
(<literal>inversejoinColumns</literal>).</para>
- </sect5>
+ </section>
- <sect5 id="entity-mapping-association-collection-manytomany-default"
- revision="1">
+ <section id="entity-mapping-association-collection-manytomany-default"
+ revision="1">
<title>Defaults</title>
<para>Without describing any physical mapping, a unidirectional
@@ -1555,14 +1580,14 @@
name, <keycap>_</keycap>, trainer id) and a foreign key
<literal>trainedTigers_id</literal> to <literal>Monkey</literal>
(property name, <keycap>_</keycap>, Tiger primary column).</para>
- </sect5>
- </sect4>
+ </section>
+ </section>
- <sect4 id="eentity-mapping-association-collection-manytomany"
- revision="">
+ <section id="eentity-mapping-association-collection-manytomany"
+ revision="">
<title>Many-to-many</title>
- <sect5>
+ <section>
<title>Definition</title>
<para>A many-to-many association is defined logically using the
@@ -1619,9 +1644,9 @@
describe the physical mapping: a simple
<literal>mappedBy</literal> argument containing the owner side
property name bind the two.</para>
- </sect5>
+ </section>
- <sect5>
+ <section>
<title>Default values</title>
<para>As any other annotations, most values are guessed in a many
@@ -1691,11 +1716,11 @@
the <literal>Store</literal> table. The
<literal>customers_id</literal> column is a foreign key to the
<literal>Customer</literal> table.</para>
- </sect5>
- </sect4>
- </sect3>
+ </section>
+ </section>
+ </section>
- <sect3 id="entity-mapping-association-cascade">
+ <section id="entity-mapping-association-cascade">
<title>Transitive persistence with cascading</title>
<para>You probably have noticed the <literal>cascade</literal>
@@ -1706,23 +1731,29 @@
<itemizedlist>
<listitem>
- CascadeType.PERSIST: cascades the persist (create) operation to associated entities persist() is called or if the entity is managed
+ <para>CascadeType.PERSIST: cascades the persist (create) operation
+ to associated entities persist() is called or if the entity is
+ managed</para>
</listitem>
<listitem>
- CascadeType.MERGE: cascades the merge operation to associated entities if merge() is called or if the entity is managed
+ <para>CascadeType.MERGE: cascades the merge operation to
+ associated entities if merge() is called or if the entity is
+ managed</para>
</listitem>
<listitem>
- CascadeType.REMOVE: cascades the remove operation to associated entities if delete() is called
+ <para>CascadeType.REMOVE: cascades the remove operation to
+ associated entities if delete() is called</para>
</listitem>
<listitem>
- CascadeType.REFRESH: cascades the refresh operation to associated entities if refresh() is called
+ <para>CascadeType.REFRESH: cascades the refresh operation to
+ associated entities if refresh() is called</para>
</listitem>
<listitem>
- CascadeType.ALL: all of the above
+ <para>CascadeType.ALL: all of the above</para>
</listitem>
</itemizedlist>
@@ -1734,9 +1765,9 @@
<para>Please refer to the chapter 6.3 of the EJB3 specification for
more information on cascading and create/merge semantics.</para>
- </sect3>
+ </section>
- <sect3 id="entity-mapping-association-fetching" revision="1">
+ <section id="entity-mapping-association-fetching" revision="1">
<title>Association fetching</title>
<para>You have the ability to either eagerly or lazily fetch
@@ -1758,10 +1789,10 @@
allows you to override laziness when doing a particular query. This is
very useful to improve performance and is decided on a use case to use
case basis.</para>
- </sect3>
- </sect2>
+ </section>
+ </section>
- <sect2>
+ <section>
<title>Mapping composite primary and foreign keys</title>
<para>Composite primary keys use a embedded class as the primary key
@@ -1853,9 +1884,9 @@
<para>Note the explicit usage of the
<literal>referencedColumnName</literal>.</para>
- </sect2>
+ </section>
- <sect2>
+ <section>
<title>Mapping secondary tables</title>
<para>You can map a single entity bean to several tables using the
@@ -1913,14 +1944,14 @@
<para>Check out the JBoss EJB 3 tutorial or the Hibernate Annotations
unit test suite for more examples.</para>
- </sect2>
- </sect1>
+ </section>
+ </section>
- <sect1 id="entity-mapping-query">
+ <section id="entity-mapping-query">
<title>Mapping Queries</title>
- <sect2 id="entity-mapping-query-hql" label="Mapping JPAQL/HQL queries"
- revision="1">
+ <section id="entity-mapping-query-hql" label="Mapping JPAQL/HQL queries"
+ revision="1">
<title>Mapping JPAQL/HQL queries</title>
<para>You can map EJBQL/HQL queries using annotations.
@@ -2032,9 +2063,9 @@
</tbody>
</tgroup>
</table>
- </sect2>
+ </section>
- <sect2 id="entity-mapping-query-native" revision="2">
+ <section id="entity-mapping-query-native" revision="2">
<title>Mapping native queries</title>
<para>You can also map a native query (ie a plain SQL query). To achieve
@@ -2255,10 +2286,10 @@
introduced: <literal>org.hibernate.callable</literal> which can be true
or false depending on whether the query is a stored procedure or
not.</para>
- </sect2>
- </sect1>
+ </section>
+ </section>
- <sect1 id="entity-hibspec" xreflabel="Hibernate Annotation Extensions">
+ <section id="entity-hibspec" xreflabel="Hibernate Annotation Extensions">
<title>Hibernate Annotation Extensions</title>
<para>Hibernate 3.1 offers a variety of additional annotations that you
@@ -2270,7 +2301,7 @@
<classname>org.hibernate.annotations</classname> package contains all
these annotations extensions.</para>
- <sect2 id="entity-hibspec-entity" revision="4">
+ <section id="entity-hibspec-entity" revision="4">
<title>Entity</title>
<para>You can fine tune some of the actions done by Hibernate on
@@ -2280,27 +2311,33 @@
additional metadata that may be needed beyond what is defined in the
standard <literal>@Entity</literal> <itemizedlist>
<listitem>
- mutable: whether this entity is mutable or not
+ <para>mutable: whether this entity is mutable or not</para>
</listitem>
<listitem>
- dynamicInsert: allow dynamic SQL for inserts
+ <para>dynamicInsert: allow dynamic SQL for inserts</para>
</listitem>
<listitem>
- dynamicUpdate: allow dynamic SQL for updates
+ <para>dynamicUpdate: allow dynamic SQL for updates</para>
</listitem>
<listitem>
- selectBeforeUpdate: Specifies that Hibernate should never perform an SQL UPDATE unless it is certain that an object is actually modified.
+ <para>selectBeforeUpdate: Specifies that Hibernate should never
+ perform an SQL UPDATE unless it is certain that an object is
+ actually modified.</para>
</listitem>
<listitem>
- polymorphism: whether the entity polymorphism is of PolymorphismType.IMPLICIT (default) or PolymorphismType.EXPLICIT
+ <para>polymorphism: whether the entity polymorphism is of
+ PolymorphismType.IMPLICIT (default) or
+ PolymorphismType.EXPLICIT</para>
</listitem>
<listitem>
- optimisticLock: optimistic locking strategy (OptimisticLockType.VERSION, OptimisticLockType.NONE, OptimisticLockType.DIRTY or OptimisticLockType.ALL)
+ <para>optimisticLock: optimistic locking strategy
+ (OptimisticLockType.VERSION, OptimisticLockType.NONE,
+ OptimisticLockType.DIRTY or OptimisticLockType.ALL)</para>
</listitem>
</itemizedlist></para>
@@ -2423,15 +2460,15 @@
@Entity
@OnDelete(action=OnDeleteAction.CASCADE)
public class Carrot extends Vegetable { ... }</programlisting></para>
- </sect2>
+ </section>
- <sect2 id="entity-hibspec-identifier" label="Identifier" revision="2">
+ <section id="entity-hibspec-identifier" label="Identifier" revision="2">
<title>Identifier</title>
<para>Hibernate Annotations goes beyond the Java Persistence
specification when defining identifiers.</para>
- <sect3>
+ <section>
<title>Generators</title>
<para><literal><literal>@org.hibernate.annotations.GenericGenerator</literal>
@@ -2478,9 +2515,9 @@
}
)
package org.hibernate.test.model</programlisting>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>@NaturalId</title>
<para>While not used as identifier property, some (group of)
@@ -2519,13 +2556,13 @@
<para>Note that the group of properties representing the natural
identifier have to be unique (Hibernate will generate a unique
constraint if the database schema is generated).</para>
- </sect3>
- </sect2>
+ </section>
+ </section>
- <sect2 id="entity-hibspec-property" revision="2">
+ <section id="entity-hibspec-property" revision="2">
<title>Property</title>
- <sect3>
+ <section>
<title>Access type</title>
<para>The default access type is determined from the position of the
@@ -2570,8 +2607,8 @@
<itemizedlist>
<listitem>
- <para>The access type is overriden for the annotated element, if
- overriden on a class, all the properties of the given class
+ <para>The access type is overridden for the annotated element, if
+ overridden on a class, all the properties of the given class
inherit the access type.</para>
</listitem>
@@ -2689,9 +2726,9 @@
}
}
</programlisting>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Formula</title>
<para>Sometimes, you want the Database to do some computation for you
@@ -2705,9 +2742,9 @@
<para>The SQL fragment can be as complex as you want and even include
subselects.</para>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Type</title>
<para><literal>@org.hibernate.annotations.Type</literal> overrides the
@@ -2731,11 +2768,9 @@
<literal>@Type</literal> annotation.</para>
<note>
- Package level annotations are placed in a file named
-
- <filename>package-info.java</filename>
-
- in the appropriate package. Place your annotations before the package declaration.
+ <para>Package level annotations are placed in a file named
+ <filename>package-info.java</filename> in the appropriate package.
+ Place your annotations before the package declaration.</para>
</note>
<programlisting>
@@ -2802,9 +2837,9 @@
private Currency currency;
...
}</programlisting>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Index</title>
<para>You can define an index on a particular column using the
@@ -2816,9 +2851,9 @@
public String getStoryPart1() {
return storyPart1;
}</programlisting>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>@Parent</title>
<para>When inside an embeddable object, you can define one of the
@@ -2838,9 +2873,9 @@
person == person.address.owner</programlisting>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Generated properties</title>
<para>Some properties are generated at insert or update time by your
@@ -2867,9 +2902,9 @@
<para><literal>@Version</literal> properties cannot be
<literal>@Generated(INSERT)</literal> by design, it has to be either
<literal>NEVER</literal> or <literal>ALWAYS</literal>.</para>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>@Target</title>
<para>Sometimes, the type guessed by reflection is not the one you
@@ -2886,9 +2921,9 @@
}</programlisting>
<para></para>
- </sect3>
+ </section>
- <sect3>
+ <section>
<title>Optimistic lock</title>
<para>It is sometimes useful to avoid increasing the version number
@@ -2898,10 +2933,10 @@
<para>More formally, specifies that updates to this property do not
require acquisition of the optimistic lock.</para>
- </sect3>
- </sect2>
+ </section>
+ </section>
- <sect2 id="entity-hibspec-inheritance" revision="3">
+ <section id="entity-hibspec-inheritance" revision="3">
<title>Inheritance</title>
<para>SINGLE_TABLE is a very powerful strategy but sometimes, and
@@ -2939,9 +2974,9 @@
<para>The foreign key from the <literal>Document</literal> table to the
<literal>File</literal> table will be named
<literal>FK_DOCU_FILE</literal>.</para>
- </sect2>
+ </section>
- <sect2 id="entity-hibspec-singleassoc">
+ <section id="entity-hibspec-singleassoc">
<title>Single Association related annotations</title>
<para>By default, when Hibernate cannot resolve the association because
@@ -2993,7 +3028,7 @@
alter table Child add constraint FK_PARENT foreign key (parent_id) references Parent</programlisting>
- <sect3 id="entity-hibspec-singleassoc-fetching">
+ <section id="entity-hibspec-singleassoc-fetching">
<title>Lazy options and fetching modes</title>
<para>EJB3 comes with the <literal>fetch</literal> option to define
@@ -3091,9 +3126,9 @@
</tbody>
</tgroup>
</table>
- </sect3>
+ </section>
- <sect3 id="entity-hibspec-singleassoc-any">
+ <section id="entity-hibspec-singleassoc-any">
<title>@Any</title>
<para>The <classname>@Any</classname> annotation defines a polymorphic
@@ -3148,38 +3183,43 @@
public Property getMainProperty() {
return mainProperty;
}</programlisting>
- </sect3>
- </sect2>
+ </section>
+ </section>
- <sect2 id="entity-hibspec-collection" revision="2">
+ <section id="entity-hibspec-collection" revision="2">
<title>Collection related annotations</title>
- <sect3 id="entity-hibspec-collection-enhance" revision="3">
+ <section id="entity-hibspec-collection-enhance" revision="3">
<title>Enhance collection settings</title>
<para>It is possible to set <itemizedlist>
<listitem>
- the batch size for collections using @BatchSize
+ <para>the batch size for collections using @BatchSize</para>
</listitem>
<listitem>
- the where clause, using @Where (applied on the target entity) or @WhereJoinTable (applied on the association table)
+ <para>the where clause, using @Where (applied on the target
+ entity) or @WhereJoinTable (applied on the association
+ table)</para>
</listitem>
<listitem>
- the check clause, using @Check
+ <para>the check clause, using @Check</para>
</listitem>
<listitem>
- the SQL order by clause, using @OrderBy
+ <para>the SQL order by clause, using @OrderBy</para>
</listitem>
<listitem>
- the delete cascade strategy through @OnDelete(action=OnDeleteAction.CASCADE)
+ <para>the delete cascade strategy through
+ @OnDelete(action=OnDeleteAction.CASCADE)</para>
</listitem>
<listitem>
- the collection immutability using @Immutable: if set specifies that the elements of the collection never change (a minor performance optimization in some cases)
+ <para>the collection immutability using @Immutable: if set
+ specifies that the elements of the collection never change (a
+ minor performance optimization in some cases)</para>
</listitem>
<listitem>
@@ -3230,12 +3270,12 @@
alter table Man_Woman add constraint TO_WOMAN_FK foreign key (woman_id) references Woman
alter table Man_Woman add constraint TO_MAN_FK foreign key (man_id) references Man</programlisting>
- </sect3>
+ </section>
- <sect3 id="entity-hibspec-collection-extratype" revision="1">
+ <section id="entity-hibspec-collection-extratype" revision="1">
<title>Extra collection types</title>
- <sect4>
+ <section>
<title>List</title>
<para>Beyond EJB3, Hibernate Annotations supports true
@@ -3259,9 +3299,9 @@
limitations of it, consider using
<literal>@CollectionId</literal>.</para>
</note>
- </sect4>
+ </section>
- <sect4 id="entity-hibspec-collection-extratype-map" revision="1">
+ <section id="entity-hibspec-collection-extratype-map" revision="1">
<title>Map</title>
<para>Hibernate Annotations also supports true Map mappings, if
@@ -3285,10 +3325,10 @@
private Map<Luggage, Size> sizePerLuggage = new HashMap<Luggage, Size>();</programlisting>
<para></para>
- </sect4>
+ </section>
- <sect4 id="entity-hibspec-collection-extratype-indexbidir"
- revision="2">
+ <section id="entity-hibspec-collection-extratype-indexbidir"
+ revision="2">
<title>Bidirectional association with indexed collections</title>
<para>A bidirectional association where one end is an indexed
@@ -3347,9 +3387,9 @@
<para>Note that in this mapping, the collection-valued end of the
association is responsible for updating the foreign key.</para>
- </sect4>
+ </section>
- <sect4>
+ <section>
<title>Bag with primary key</title>
<para>Another interesting feature is the ability to define a
@@ -3378,9 +3418,9 @@
private Collection<Stamp> visaStamp = new ArrayList();
...
}</programlisting>
- </sect4>
+ </section>
- <sect4>
+ <section>
<title>Collection of element or composite elements</title>
<para>Hibernate Annotations also supports collections of core types
@@ -3520,9 +3560,9 @@
elements the old way still work but is considered deprecated and
is going to be unsupported in future releases</para>
</note>
- </sect4>
+ </section>
- <sect4>
+ <section>
<title>@ManyToAny</title>
<para><classname>@ManyToAny</classname> allows polymorphic
@@ -3552,11 +3592,11 @@
<classname>@ManyToAny</classname> can use named
<classname>@AnyDef</classname>s, see <xref
linkend="entity-hibspec-singleassoc-any" /> for more info.</para>
- </sect4>
- </sect3>
- </sect2>
+ </section>
+ </section>
+ </section>
- <sect2 id="entity-hibspec-cascade" xreflabel="Cascade">
+ <section id="entity-hibspec-cascade" xreflabel="Cascade">
<title>Cascade</title>
<para>Hibernate offers more operations than the Java Persistence
@@ -3625,9 +3665,9 @@
<para>It is recommended to use @Cascade to compliment @*To*(cascade=...)
as shown in the previous example.</para>
- </sect2>
+ </section>
- <sect2>
+ <section>
<title>Cache</title>
<para>In order to optimize your database accesses, you can activate the
@@ -3654,11 +3694,11 @@
<programlistingco>
<areaspec>
- <area coords="2 55" id="hm1" />
+ <area coords="2 55" id="cache-hm1" />
- <area coords="3 55" id="hm2" />
+ <area coords="3 55" id="cache-hm2" />
- <area coords="4 55" id="hm3" />
+ <area coords="4 55" id="cache-hm3" />
</areaspec>
<programlisting>@Cache(
@@ -3668,26 +3708,26 @@
)</programlisting>
<calloutlist>
- <callout arearefs="hm1">
+ <callout arearefs="cache-hm1">
<para>usage: the given cache concurrency strategy (NONE,
READ_ONLY, NONSTRICT_READ_WRITE, READ_WRITE, TRANSACTIONAL)</para>
</callout>
- <callout arearefs="hm2">
+ <callout arearefs="cache-hm2">
<para>region (optional): the cache region (default to the fqcn of
the class or the fq role name of the collection)</para>
</callout>
- <callout arearefs="hm3">
+ <callout arearefs="cache-hm3">
<para><literal>include</literal> (optional): all to include all
properties, non-lazy to only include non lazy properties (default
all).</para>
</callout>
</calloutlist>
</programlistingco>
- </sect2>
+ </section>
- <sect2 id="entity-hibspec-filters">
+ <section id="entity-hibspec-filters">
<title>Filters</title>
<para>Hibernate has the ability to apply arbitrary filters on top of
@@ -3733,9 +3773,9 @@
//filter on the association table
@FilterJoinTable(name="security", condition=":userlevel >= requredLevel")
public Set<Forest> getForests() { ... }</programlisting>
- </sect2>
+ </section>
- <sect2 id="entity-hibspec-query">
+ <section id="entity-hibspec-query">
<title>Queries</title>
<para>Since Hibernate has more features on named queries than the one
@@ -3794,9 +3834,9 @@
<literal>@javax.persistence.NamedQuery</literal> annotations through the
detyped <literal>@QueryHint</literal>. Another key advantage is the
ability to set those annotations at a package level.</para>
- </sect2>
+ </section>
- <sect2 id="entity-hibspec-customsql" revision="1">
+ <section id="entity-hibspec-customsql" revision="1">
<title>Custom SQL for CRUD operations</title>
<para>Hibernate gives you the ability to override every single SQL
@@ -3893,9 +3933,9 @@
<para>The previous example also show that you can give a comment to a
given table (promary or secondary): This comment will be used for DDL
generation.</para>
- </sect2>
+ </section>
- <sect2>
+ <section>
<title>Tuplizer</title>
<para><classname>org.hibernate.tuple.Tuplizer</classname>, and its
@@ -3936,6 +3976,6 @@
}</programlisting>
- </sect2>
- </sect1>
+ </section>
+ </section>
</chapter>
\ No newline at end of file
14 years, 2 months