Hibernate SVN: r18931 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/test and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: smarlow(a)redhat.com
Date: 2010-03-05 17:22:05 -0500 (Fri, 05 Mar 2010)
New Revision: 18931
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java
Log:
HHH-4972 javax.persistence.query.timeout and javax.persistence.lock.timeout can be passed when creating an EMF
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-03-05 18:17:36 UTC (rev 18930)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-03-05 22:22:05 UTC (rev 18931)
@@ -118,6 +118,7 @@
entityManagerSpecificProperties.add( AvailableSettings.FLUSH_MODE );
entityManagerSpecificProperties.add( AvailableSettings.SHARED_CACHE_RETRIEVE_MODE );
entityManagerSpecificProperties.add( AvailableSettings.SHARED_CACHE_STORE_MODE );
+ entityManagerSpecificProperties.add( QueryHints.SPEC_HINT_TIMEOUT );
}
private EntityManagerFactoryImpl entityManagerFactory;
@@ -168,6 +169,17 @@
);
}
+ private Query applyProperties(Query query) {
+ if ( lockOptions.getLockMode() != LockMode.NONE ) {
+ query.setLockMode( getLockMode(lockOptions.getLockMode()));
+ }
+ Object queryTimeout;
+ if ( (queryTimeout = getProperties().get(QueryHints.SPEC_HINT_TIMEOUT)) != null ) {
+ query.setHint ( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
+ }
+ return query;
+ }
+
private CacheRetrieveMode currentCacheRetrieveMode() {
return determineCacheRetrieveMode( properties );
}
@@ -248,7 +260,7 @@
public Query createQuery(String jpaqlString) {
try {
- return new QueryImpl<Object>( getSession().createQuery( jpaqlString ), this );
+ return applyProperties( new QueryImpl<Object>( getSession().createQuery( jpaqlString ), this ) );
}
catch ( HibernateException he ) {
throw convert( he );
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java 2010-03-05 18:17:36 UTC (rev 18930)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/TestCase.java 2010-03-05 22:22:05 UTC (rev 18931)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -134,6 +134,12 @@
return isolatedEm;
}
+ protected EntityManager createIsolatedEntityManager(Map props) {
+ EntityManager isolatedEm = factory.createEntityManager(props);
+ isolatedEms.add( isolatedEm );
+ return isolatedEm;
+ }
+
/**
* always reopen a new EM and clse the existing one
*/
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java 2010-03-05 18:17:36 UTC (rev 18930)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/lock/LockTest.java 2010-03-05 22:22:05 UTC (rev 18931)
@@ -601,7 +601,96 @@
}
}
+ public void testQueryTimeoutEMProps() throws Exception {
+ // TODO: replace dialect instanceof test with a Dialect.hasCapability
+ if ( ! (getDialect() instanceof Oracle10gDialect)) {
+ log.info("skipping testQueryTimeout");
+ return;
+ }
+ EntityManager em = getOrCreateEntityManager();
+ Map queryTimeoutProps = new HashMap();
+ queryTimeoutProps.put("javax.persistence.query.timeout", new Integer(500) ); // 1 sec timeout (should round up)
+ final EntityManager em2 = createIsolatedEntityManager(queryTimeoutProps);
+ Lock lock = new Lock();
+ Thread t = null;
+ FutureTask<Boolean> bgTask = null;
+ final CountDownLatch latch = new CountDownLatch(1);
+ try {
+ lock.setName( "testQueryTimeout" );
+ em.getTransaction().begin();
+ em.persist( lock );
+ em.getTransaction().commit();
+ em.clear();
+
+ em.getTransaction().begin();
+ lock = em.getReference( Lock.class, lock.getId() );
+ em.lock( lock, LockModeType.PESSIMISTIC_WRITE );
+ final Integer id = lock.getId();
+ lock.getName(); // force entity to be read
+ log.info("testQueryTimeout: got write lock");
+
+ bgTask = new FutureTask<Boolean>( new Callable() {
+ public Boolean call() {
+ try {
+ boolean timedOut = false; // true (success) if LockTimeoutException occurred
+ em2.getTransaction().begin();
+ log.info( "testQueryTimeout: (BG) about to read write-locked entity" );
+ // we should block on the following read
+ Lock lock2 = em2.getReference( Lock.class, id );
+ lock2.getName(); // force entity to be read
+ log.info( "testQueryTimeout: (BG) read write-locked entity" );
+ try {
+ // we should block on the following read
+ Query query = em2.createQuery(
+ "select L from Lock_ L where L.id < 10000 ");
+ query.setLockMode( LockModeType.PESSIMISTIC_READ );
+ List<Lock> resultList = query.getResultList();
+ String name = resultList.get(0).getName(); // force entity to be read
+ log.info( "testQueryTimeout: name read =" + name );
+ }
+ catch( QueryTimeoutException e) {
+ // success
+ log.info( "testQueryTimeout: (BG) got expected timeout exception" );
+ timedOut = true;
+ }
+ catch ( Throwable e) {
+ log.info( "testQueryTimeout: Expected LockTimeoutException but got unexpected exception", e );
+ }
+ em2.getTransaction().commit();
+ return new Boolean( timedOut );
+ }
+ finally {
+ latch.countDown(); // signal that we finished
+ }
+ }
+ } );
+ t = new Thread(bgTask);
+ t.setDaemon( true );
+ t.setName( "testQueryTimeout (bg)" );
+ t.start();
+ boolean latchSet = latch.await( 10, TimeUnit.SECONDS ); // should return quickly on success
+ assertTrue( "background test thread finished (lock timeout is broken)", latchSet);
+ assertTrue( "background test thread timed out on lock attempt", bgTask.get().booleanValue() );
+ em.getTransaction().commit();
+ }
+ finally {
+ if ( em.getTransaction().isActive() ) {
+ em.getTransaction().rollback();
+ }
+ if ( t != null) { // wait for background thread to finish before deleting entity
+ t.join();
+ }
+ em.getTransaction().begin();
+ lock = em.getReference( Lock.class, lock.getId() );
+ em.remove( lock );
+ em.getTransaction().commit();
+ em.close();
+ em2.close();
+ }
+ }
+
+
public Class[] getAnnotatedClasses() {
return new Class[]{
Lock.class,
14 years, 10 months
Hibernate SVN: r18930 - annotations/tags.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-05 13:17:36 -0500 (Fri, 05 Mar 2010)
New Revision: 18930
Added:
annotations/tags/3_3_1_GA_CP03/
Log:
tag for eap 4.3 cp08
Copied: annotations/tags/3_3_1_GA_CP03 (from rev 18929, annotations/branches/v3_3_1_GA_CP)
14 years, 10 months
Hibernate SVN: r18929 - in annotations/branches/v3_3_1_GA_CP: doc/reference/en and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-05 13:16:28 -0500 (Fri, 05 Mar 2010)
New Revision: 18929
Modified:
annotations/branches/v3_3_1_GA_CP/build.xml
annotations/branches/v3_3_1_GA_CP/changelog.txt
annotations/branches/v3_3_1_GA_CP/doc/reference/en/master.xml
annotations/branches/v3_3_1_GA_CP/src/java/org/hibernate/cfg/annotations/Version.java
Log:
JBPAPP-3844 upgrade ann to 3.3.1.GA.CP03
Modified: annotations/branches/v3_3_1_GA_CP/build.xml
===================================================================
--- annotations/branches/v3_3_1_GA_CP/build.xml 2010-03-05 18:08:08 UTC (rev 18928)
+++ annotations/branches/v3_3_1_GA_CP/build.xml 2010-03-05 18:16:28 UTC (rev 18929)
@@ -16,7 +16,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Annotations"/>
<property name="name" value="hibernate-annotations"/>
- <property name="version" value="3.3.1.GA.CP02"/>
+ <property name="version" value="3.3.1.GA.CP03"/>
<property name="javadoc.packagenames" value="org.hibernate.*"/>
<property name="jdbc.dir" value="jdbc"/>
<property name="copy.test" value="true"/>
Modified: annotations/branches/v3_3_1_GA_CP/changelog.txt
===================================================================
--- annotations/branches/v3_3_1_GA_CP/changelog.txt 2010-03-05 18:08:08 UTC (rev 18928)
+++ annotations/branches/v3_3_1_GA_CP/changelog.txt 2010-03-05 18:16:28 UTC (rev 18929)
@@ -1,6 +1,18 @@
Hibernate Annotations Changelog
===============================
+3.3.1.GA.CP03
+---------------------
+** Bug
+ * [JBPAPP-2082 / ANN841] - Bidirectional indexed collection mapped incorrectly for IndexedCollectionTest
+ * [JBPAPP-3057] - DB2 - Assertion Failed in EntityTest.testColumn
+ * [JBPAPP-3068] - in MySQL, BLOBS should specify a length/number of bytes for fields in index
+ * [JBPAPP-3384 / HHH-4257] - map key type no longer inferred correctly, throws exception at runtime
+ * [JBPAPP-3565 / HHH-4851] - OneToOneSecondPass Metadata is mistakenly interpreted
+ * [JBPAPP-3799 / HHH-4773] - unit tests fail cos db2 doesn't allow primary key column nullable
+** Task
+ * [JBPAPP-3837] - clean up build script of annotations
+
3.3.1.GA.CP02
---------------------
Modified: annotations/branches/v3_3_1_GA_CP/doc/reference/en/master.xml
===================================================================
--- annotations/branches/v3_3_1_GA_CP/doc/reference/en/master.xml 2010-03-05 18:08:08 UTC (rev 18928)
+++ annotations/branches/v3_3_1_GA_CP/doc/reference/en/master.xml 2010-03-05 18:16:28 UTC (rev 18929)
@@ -12,7 +12,7 @@
<subtitle>Reference Guide</subtitle>
- <releaseinfo>3.3.1.GA.CP02</releaseinfo>
+ <releaseinfo>3.3.1.GA.CP03</releaseinfo>
<mediaobject>
<imageobject>
Modified: annotations/branches/v3_3_1_GA_CP/src/java/org/hibernate/cfg/annotations/Version.java
===================================================================
--- annotations/branches/v3_3_1_GA_CP/src/java/org/hibernate/cfg/annotations/Version.java 2010-03-05 18:08:08 UTC (rev 18928)
+++ annotations/branches/v3_3_1_GA_CP/src/java/org/hibernate/cfg/annotations/Version.java 2010-03-05 18:16:28 UTC (rev 18929)
@@ -8,7 +8,7 @@
* @author Emmanuel Bernard
*/
public class Version {
- public static final String VERSION = "3.3.1.GA.CP02";
+ public static final String VERSION = "3.3.1.GA.CP03";
private static Log log = LogFactory.getLog( Version.class );
static {
14 years, 10 months
Hibernate SVN: r18928 - core/tags.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-05 13:08:08 -0500 (Fri, 05 Mar 2010)
New Revision: 18928
Added:
core/tags/JBOSS_EAP_3_2_4_SP1_CP10/
Log:
tag for eap 4.3 cp08
Copied: core/tags/JBOSS_EAP_3_2_4_SP1_CP10 (from rev 18927, core/branches/Branch_3_2_4_SP1_CP)
14 years, 10 months
Hibernate SVN: r18927 - in core/branches/Branch_3_2_4_SP1_CP: src/org/hibernate/cfg and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-05 13:07:01 -0500 (Fri, 05 Mar 2010)
New Revision: 18927
Modified:
core/branches/Branch_3_2_4_SP1_CP/build.xml
core/branches/Branch_3_2_4_SP1_CP/changelog.txt
core/branches/Branch_3_2_4_SP1_CP/readme.txt
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/cfg/Environment.java
Log:
JBPAPP-3844 upgrade core version to 3.2.4.sp1.cp10
Modified: core/branches/Branch_3_2_4_SP1_CP/build.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/build.xml 2010-03-05 15:23:34 UTC (rev 18926)
+++ core/branches/Branch_3_2_4_SP1_CP/build.xml 2010-03-05 18:07:01 UTC (rev 18927)
@@ -24,7 +24,7 @@
<property name="version.minor" value="2"/>
<property name="version.micro" value="4"/>
<property name="version.qualifier" value="sp1"/>
- <property name="version.cp" value="cp09"/>
+ <property name="version.cp" value="cp10"/>
<property name="version.full" value="${version.major}.${version.minor}.${version.micro}.${version.qualifier}.${version.cp}"/>
<property name="version.major_minor" value="${version.major}.${version.minor}"/>
<property name="fullname" value="${name}-${version.full}"/>
Modified: core/branches/Branch_3_2_4_SP1_CP/changelog.txt
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/changelog.txt 2010-03-05 15:23:34 UTC (rev 18926)
+++ core/branches/Branch_3_2_4_SP1_CP/changelog.txt 2010-03-05 18:07:01 UTC (rev 18927)
@@ -4,7 +4,22 @@
match the actual issue resolution (i.e. a bug might not be a bug). Please
refer to the particular case on JIRA using the issue tracking number to learn
more about each case.
+Changes in version 3.2.4.sp1.cp10
+-------------------------------------------
+** Bug
+ * [JBPAPP-906 / HHH-2990] - Bad usage of ClassLoader.loadClass() for Java6 in SerializationHelper$CustomObjectInputStream - deserialization bottleneck for arrays
+ * [JBPAPP-2943 / HHH-4457] - SchemaUpdate fails on Sybase ASE 15 when a new column is added without a default value
+ * [JBPAPP-3056] - DB2 v9.1 - Test fails due to "Invalid use of a parameter marker."
+ * [JBPAPP-3067 / HHH-4567] - Tests in MySQL using different case for objects as defined in configuration
+ * [JBPAPP-3089 / HHH-2166] - Long "in" lists in queries results in a Java stack overflow exception.
+ * [JBPAPP-3098 / HHH-4065] - Incorrect SQL is used for HQL if the number of values for a filter collection parameter is changed
+ * [JBPAPP-3115] - update HREFs for JDK from jdk1.4 to jdk1.5
+ * [JBPAPP-3173 / HHH-4614] - (javassist)Instrumented model with abstract MappedSuperclass and field access doesn't work
+ * [JBPAPP-3211 / HHH-3159] - Oracle 11g - desupport of oracle.jdbc.driver
+ * [JBPAPP-3371 / HHH-4769] - on MySQL, HQL function ROUND always returns an Integer, it truncate the decimal part of Double number.
+ * [JBPAPP-3487 / HHH-4825] - wrong alias used in table-pre-class Inheritance strategy
+
Changes in version 3.2.4.sp1.cp09
-------------------------------------------
Modified: core/branches/Branch_3_2_4_SP1_CP/readme.txt
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/readme.txt 2010-03-05 15:23:34 UTC (rev 18926)
+++ core/branches/Branch_3_2_4_SP1_CP/readme.txt 2010-03-05 18:07:01 UTC (rev 18927)
@@ -1,6 +1,6 @@
Hibernate - Relational Persistence for Idiomatic Java
=====================================================
-version 3.2.4.sp1.cp09
+version 3.2.4.sp1.cp10
Copyright © 2009 Red Hat, Inc.
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/cfg/Environment.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/cfg/Environment.java 2010-03-05 15:23:34 UTC (rev 18926)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/cfg/Environment.java 2010-03-05 18:07:01 UTC (rev 18927)
@@ -153,7 +153,7 @@
*/
public final class Environment {
- public static final String VERSION = "3.2.4.sp1.cp09";
+ public static final String VERSION = "3.2.4.sp1.cp10";
/**
* <tt>ConnectionProvider</tt> implementor to use when obtaining connections
14 years, 10 months
Hibernate SVN: r18926 - core/trunk/annotations/src/main/docbook/en/modules.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-03-05 10:23:34 -0500 (Fri, 05 Mar 2010)
New Revision: 18926
Modified:
core/trunk/annotations/src/main/docbook/en/modules/entity.xml
core/trunk/annotations/src/main/docbook/en/modules/setup.xml
Log:
HHH-4812 documentation
Modified: core/trunk/annotations/src/main/docbook/en/modules/entity.xml
===================================================================
--- core/trunk/annotations/src/main/docbook/en/modules/entity.xml 2010-03-05 00:56:10 UTC (rev 18925)
+++ core/trunk/annotations/src/main/docbook/en/modules/entity.xml 2010-03-05 15:23:34 UTC (rev 18926)
@@ -3207,7 +3207,7 @@
@Where(clause="1=1")
@org.hibernate.annotations.Table(name="Forest", indexes = { @Index(name="idx", columnNames = { "name", "length" } ) } )
@Persister(impl=MyEntityPersister.class)
-public class Forest { ... }</programlisting><programlisting>@Entity
+public class Forest { ... }</programlisting> <programlisting>@Entity
@Inheritance(
strategy=InheritanceType.JOINED
)
@@ -3614,7 +3614,8 @@
alter table Child add constraint FK_PARENT foreign key (parent_id) references Parent</programlisting>
<section id="entity-hibspec-singleassoc-fetching">
- <title>Lazy options and fetching modes</title>
+ <title id="section-lazy-options-fetching-modes">Lazy options and
+ fetching modes</title>
<para>JPA comes with the <literal>fetch</literal> option to define
lazy loading and fetching modes, however Hibernate has a much more
@@ -4301,5 +4302,63 @@
public void setCountry(Country country);
}</programlisting>
</section>
+
+ <section>
+ <title>Fetch profiles</title>
+
+ <para>In <xref linkend="section-lazy-options-fetching-modes" /> we have
+ seen how to affect the fetching strategy for associated objects using
+ the <classname>@Fetch</classname> annotation. An alternative approach is
+ a so called fetch profile. A fetch profile is a named configuration
+ associated with the <classname>org.hibernate.SessionFactory</classname>
+ which gets enabled on the <classname>org.hibernate.Session.</classname>
+ Once enabled on a <classname>org.hibernate.Session</classname>, the
+ fetch profile will be in affect for that session until it is explicitly
+ disabled. Lets look at an example:</para>
+
+ <para><programlisting>@Entity
+<emphasis role="bold">@FetchProfile(name = "customer-with-orders", fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN)
+})</emphasis>
+public class Customer {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ private String name;
+
+ private long customerNumber;
+
+ @OneToMany
+ private Set<Order> orders;
+
+ // standard getter/setter
+ ...
+}</programlisting>In the normal case the orders association would be lazy
+ loaded by Hibernate, but in a usecase where it is more efficient to load
+ the customer and their orders together you could do something like
+ this:</para>
+
+ <programlisting>Session session = ...;
+session.enableFetchProfile( "customer-with-orders" ); // name matches @FetchProfile name
+Customer customer = (Customer) session.get( Customer.class, customerId );
+session.disableFetchProfile( "customer-with-orders" ); // or just close the session
+...</programlisting>
+
+ <note>
+ <para>Fetch profile definitions are global and it does not matter on
+ which class you place them. You can place the
+ <classname>@FetchProfile</classname> annotation either onto a class or
+ package (package-info.java). In order to define multiple fetch
+ profiles for the same class or package
+ <classname>@FetchProfiles</classname> can be used.</para>
+ </note>
+
+ <para>Currently only join style fetch profiles are supported, but they
+ plan is to support additional styles. See <ulink
+ url="http://opensource.atlassian.com/projects/hibernate/browse/HHH-3414">HHH-3414</ulink>
+ for details. Refer also to the discussion about fetch profiles in the
+ Hibernate Core documentation.</para>
+ </section>
</section>
</chapter>
Modified: core/trunk/annotations/src/main/docbook/en/modules/setup.xml
===================================================================
--- core/trunk/annotations/src/main/docbook/en/modules/setup.xml 2010-03-05 00:56:10 UTC (rev 18925)
+++ core/trunk/annotations/src/main/docbook/en/modules/setup.xml 2010-03-05 15:23:34 UTC (rev 18926)
@@ -51,7 +51,7 @@
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
- <artifactId>hibernate-annotations</artifactId>
+ <artifactId>hibernate-core</artifactId>
<version>${hibernate-core-version}</version>
</dependency>
</dependencies>
@@ -66,8 +66,8 @@
<para>First, set up your classpath (after you have created a new project
in your favorite IDE): <itemizedlist>
<listitem>
- <para>Copy <filename>hibernate-core.jar</filename> and required 3rd
- party library files.</para>
+ <para>Copy all Hibernate3 core and required 3rd party library
+ files.</para>
</listitem>
<listitem>
@@ -97,7 +97,7 @@
<filename>hibernate-validator.jar</filename> and
<filename>validation-api.jar</filename> in your classpath. Alternatively
add the following dependency in your
- <filename>pom.xml</filename>.<programlisting><project ...>
+ <filename>pom.xml</filename>.<programlisting><project>
...
<dependencies>
<dependency>
@@ -105,7 +105,9 @@
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator-version}</version>
</dependency>
+ ...
</dependencies>
+ ...
</project></programlisting></para>
<para>If you wish to use <ulink
@@ -114,7 +116,7 @@
<filename>hibernate-search.jar</filename> and
<filename>lucene-core-x.y.z.jar</filename> in your classpath.
Alternatively add the following dependency in your
- <filename>pom.xml</filename>.<programlisting><project ...>
+ <filename>pom.xml</filename>.<programlisting><project>
...
<dependencies>
<dependency>
@@ -122,7 +124,9 @@
<artifactId>hibernate-search</artifactId>
<version>${hibernate-search-version}</version>
</dependency>
+ ...
</dependencies>
+ ...
</project></programlisting></para>
<para>We recommend you use the JPA 2 APIs to bootstrap Hibernate (see the
@@ -198,7 +202,7 @@
.addAnnotatedClass(Dog.class)</emphasis>
<emphasis role="bold"> .addResource("test/animals/orm.xml")</emphasis>
.configure()
- .buildSessionFactory();</programlisting>
+ .buildSessionFactory();</programlisting>
<para>There is no other difference in the way you use Hibernate APIs with
annotations, except for this startup routine change or in the
14 years, 10 months
Hibernate SVN: r18925 - core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-04 19:56:10 -0500 (Thu, 04 Mar 2010)
New Revision: 18925
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/Dialect.java
Log:
correct typo in javadoc
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/Dialect.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/Dialect.java 2010-03-04 21:55:10 UTC (rev 18924)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/dialect/Dialect.java 2010-03-05 00:56:10 UTC (rev 18925)
@@ -362,7 +362,7 @@
// hibernate type mapping support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
- * Get the name of the Hibernate {@link org.hibernate.type.Type} associated with th given
+ * Get the name of the Hibernate {@link org.hibernate.type.Type} associated with the given
* {@link java.sql.Types} typecode.
*
* @param code The {@link java.sql.Types} typecode
@@ -433,7 +433,7 @@
}
/**
- * Retrieves a map of the dialect's registered fucntions
+ * Retrieves a map of the dialect's registered functions
* (functionName => {@link org.hibernate.dialect.function.SQLFunction}).
*
* @return The map of registered functions.
@@ -454,7 +454,7 @@
}
- // native identifier generatiion ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // native identifier generation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* The class (which implements {@link org.hibernate.id.IdentifierGenerator})
@@ -510,7 +510,7 @@
/**
* Whether this dialect have an Identity clause added to the data type or a
- * completely seperate identity data type
+ * completely separate identity data type
*
* @return boolean
*/
@@ -519,7 +519,7 @@
}
/**
- * Provided we {@link #supportsInsertSelectIdentity}, then attch the
+ * Provided we {@link #supportsInsertSelectIdentity}, then attach the
* "select identity" clause to the insert statement.
* <p/>
* Note, if {@link #supportsInsertSelectIdentity} == false then
@@ -535,7 +535,7 @@
/**
* Get the select command to use to retrieve the last generated IDENTITY
- * value for a particuar table
+ * value for a particular table
*
* @param table The table into which the insert was done
* @param column The PK column.
@@ -615,7 +615,7 @@
}
/**
- * Generate the appropriate select statement to to retreive the next value
+ * Generate the appropriate select statement to to retrieve the next value
* of a sequence.
* <p/>
* This should be a "stand alone" select statement.
@@ -629,7 +629,7 @@
}
/**
- * Generate the select expression fragment that will retreive the next
+ * Generate the select expression fragment that will retrieve the next
* value of a sequence as part of another (typically DML) statement.
* <p/>
* This differs from {@link #getSequenceNextValString(String)} in that this
@@ -787,7 +787,7 @@
}
/**
- * Does this dialect support bind variables (i.e., prepared statememnt
+ * Does this dialect support bind variables (i.e., prepared statement
* parameters) for its limit/offset?
*
* @return True if bind variables can be used; false otherwise.
@@ -862,7 +862,7 @@
* Apply s limit clause to the query.
* <p/>
* Typically dialects utilize {@link #supportsVariableLimit() variable}
- * limit caluses when they support limits. Thus, when building the
+ * limit clauses when they support limits. Thus, when building the
* select command we do not actually need to know the limit or the offest
* since we will just be using placeholders.
* <p/>
@@ -880,7 +880,7 @@
}
/**
- * Hibernate APIs explcitly state that setFirstResult() should be a zero-based offset. Here we allow the
+ * Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset. Here we allow the
* Dialect a chance to convert that value based on what the underlying db or driver will expect.
* <p/>
* NOTE: what gets passed into {@link #getLimitString(String,int,int)} is the zero-based offset. Dialects which
@@ -1138,7 +1138,7 @@
// callable statement support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
- * Registers an OUT parameter which will be returing a
+ * Registers an OUT parameter which will be returning a
* {@link java.sql.ResultSet}. How this is accomplished varies greatly
* from DB to DB, hence its inclusion (along with {@link #getResultSet}) here.
*
@@ -1194,7 +1194,7 @@
}
/**
- * Retrieve the command used to retrieve the current timestammp from the
+ * Retrieve the command used to retrieve the current timestamp from the
* database.
*
* @return The command.
14 years, 10 months
Hibernate SVN: r18924 - in core/trunk: annotations/src/main/java/org/hibernate/cfg and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-03-04 16:55:10 -0500 (Thu, 04 Mar 2010)
New Revision: 18924
Added:
core/trunk/annotations/src/main/java/org/hibernate/annotations/FetchProfile.java
core/trunk/annotations/src/main/java/org/hibernate/annotations/FetchProfiles.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/ConfigurationArtefactType.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer2.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer3.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer4.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer5.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Order.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/SupportTickets.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/package-info.java
core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/fetchprofile/
core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/ConfigurationTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/any/package-info.java
core/trunk/entitymanager/pom.xml
Log:
HHH-4812
Added @FetchProfile and @FetchProfiles annotations and wired them up. Added also some error handling in the AnnotationBinder.
Refactor the handling of precedence in the AnnotationConfiguration, because I thought I would be reusing it for the fetch profile as well, but in the end decided to jsut implement in a way that xml configured fetch profiles always win over annotation confgured ones.
Copied: core/trunk/annotations/src/main/java/org/hibernate/annotations/FetchProfile.java (from rev 18918, core/trunk/annotations/src/main/java/org/hibernate/annotations/Fetch.java)
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/annotations/FetchProfile.java (rev 0)
+++ core/trunk/annotations/src/main/java/org/hibernate/annotations/FetchProfile.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,55 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC 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.
+ *
+ * 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.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.PACKAGE;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Define the fetching strategy profile.
+ *
+ * @author Hardy Ferentschik
+ */
+@Target({ TYPE, PACKAGE })
+@Retention(RUNTIME)
+public @interface FetchProfile {
+ String name();
+
+ FetchOverride[] fetchOverrides();
+
+ @Target({ TYPE, PACKAGE })
+ @Retention(RUNTIME)
+ @interface FetchOverride {
+ Class<?> entity();
+
+ String association();
+
+ FetchMode mode();
+ }
+}
\ No newline at end of file
Copied: core/trunk/annotations/src/main/java/org/hibernate/annotations/FetchProfiles.java (from rev 18918, core/trunk/annotations/src/main/java/org/hibernate/annotations/Columns.java)
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/annotations/FetchProfiles.java (rev 0)
+++ core/trunk/annotations/src/main/java/org/hibernate/annotations/FetchProfiles.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,41 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.PACKAGE;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Target({ TYPE, PACKAGE })
+@Retention(RUNTIME)
+public @interface FetchProfiles {
+ public abstract FetchProfile[] value();
+}
\ No newline at end of file
Property changes on: core/trunk/annotations/src/main/java/org/hibernate/annotations/FetchProfiles.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-03-04 18:15:19 UTC (rev 18923)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -38,9 +38,11 @@
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
+import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
+import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.EmbeddedId;
@@ -56,6 +58,9 @@
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
+import javax.persistence.MapKeyColumn;
+import javax.persistence.MapKeyJoinColumn;
+import javax.persistence.MapKeyJoinColumns;
import javax.persistence.MappedSuperclass;
import javax.persistence.MapsId;
import javax.persistence.NamedNativeQueries;
@@ -64,6 +69,7 @@
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
+import javax.persistence.OrderColumn;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.PrimaryKeyJoinColumns;
import javax.persistence.SequenceGenerator;
@@ -72,15 +78,12 @@
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
+import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
-import javax.persistence.ElementCollection;
-import javax.persistence.CollectionTable;
-import javax.persistence.UniqueConstraint;
-import javax.persistence.MapKeyColumn;
-import javax.persistence.MapKeyJoinColumns;
-import javax.persistence.MapKeyJoinColumn;
-import javax.persistence.OrderColumn;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
@@ -96,6 +99,8 @@
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Fetch;
+import org.hibernate.annotations.FetchProfile;
+import org.hibernate.annotations.FetchProfiles;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.FilterDefs;
@@ -103,6 +108,7 @@
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;
+import org.hibernate.annotations.GenericGenerators;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;
@@ -123,7 +129,6 @@
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.annotations.Where;
-import org.hibernate.annotations.GenericGenerators;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XAnnotatedElement;
import org.hibernate.annotations.common.reflection.XClass;
@@ -133,13 +138,13 @@
import org.hibernate.cache.RegionFactory;
import org.hibernate.cfg.annotations.CollectionBinder;
import org.hibernate.cfg.annotations.EntityBinder;
+import org.hibernate.cfg.annotations.MapKeyColumnDelegator;
+import org.hibernate.cfg.annotations.MapKeyJoinColumnDelegator;
import org.hibernate.cfg.annotations.Nullability;
import org.hibernate.cfg.annotations.PropertyBinder;
import org.hibernate.cfg.annotations.QueryBinder;
import org.hibernate.cfg.annotations.SimpleValueBinder;
import org.hibernate.cfg.annotations.TableBinder;
-import org.hibernate.cfg.annotations.MapKeyColumnDelegator;
-import org.hibernate.cfg.annotations.MapKeyJoinColumnDelegator;
import org.hibernate.engine.FilterDefinition;
import org.hibernate.engine.Versioning;
import org.hibernate.id.MultipleHiLoPerTableGenerator;
@@ -167,22 +172,16 @@
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
import org.hibernate.type.TypeFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
- * JSR 175 annotation binder
- * Will read the annotation from classes, apply the
- * principles of the EJB3 spec and produces the Hibernate
- * configuration-time metamodel (the classes in the <tt>mapping</tt>
- * package)
+ * JSR 175 annotation binder which reads the annotations from classes, applies the
+ * principles of the EJB3 spec and produces the Hibernate configuration-time metamodel
+ * (the classes in the {@code org.hibernate.mapping} package)
*
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
@SuppressWarnings("unchecked")
-public final class
- AnnotationBinder {
+public final class AnnotationBinder {
/*
* Some design description
@@ -197,6 +196,7 @@
* makeSomething usually create the mapping container and is accessed by bindSomething[else]
* fillSomething take the container into parameter and fill it.
*/
+
private AnnotationBinder() {
}
@@ -205,43 +205,47 @@
public static void bindDefaults(ExtendedMappings mappings) {
Map defaults = mappings.getReflectionManager().getDefaults();
{
- List<SequenceGenerator> anns = (List<SequenceGenerator>) defaults.get( SequenceGenerator.class );
+ List<SequenceGenerator> anns = ( List<SequenceGenerator> ) defaults.get( SequenceGenerator.class );
if ( anns != null ) {
- for (SequenceGenerator ann : anns) {
+ for ( SequenceGenerator ann : anns ) {
IdGenerator idGen = buildIdGenerator( ann, mappings );
- if ( idGen != null ) mappings.addDefaultGenerator( idGen );
+ if ( idGen != null ) {
+ mappings.addDefaultGenerator( idGen );
+ }
}
}
}
{
- List<TableGenerator> anns = (List<TableGenerator>) defaults.get( TableGenerator.class );
+ List<TableGenerator> anns = ( List<TableGenerator> ) defaults.get( TableGenerator.class );
if ( anns != null ) {
- for (TableGenerator ann : anns) {
+ for ( TableGenerator ann : anns ) {
IdGenerator idGen = buildIdGenerator( ann, mappings );
- if ( idGen != null ) mappings.addDefaultGenerator( idGen );
+ if ( idGen != null ) {
+ mappings.addDefaultGenerator( idGen );
+ }
}
}
}
{
- List<NamedQuery> anns = (List<NamedQuery>) defaults.get( NamedQuery.class );
+ List<NamedQuery> anns = ( List<NamedQuery> ) defaults.get( NamedQuery.class );
if ( anns != null ) {
- for (NamedQuery ann : anns) {
+ for ( NamedQuery ann : anns ) {
QueryBinder.bindQuery( ann, mappings, true );
}
}
}
{
- List<NamedNativeQuery> anns = (List<NamedNativeQuery>) defaults.get( NamedNativeQuery.class );
+ List<NamedNativeQuery> anns = ( List<NamedNativeQuery> ) defaults.get( NamedNativeQuery.class );
if ( anns != null ) {
- for (NamedNativeQuery ann : anns) {
+ for ( NamedNativeQuery ann : anns ) {
QueryBinder.bindNativeQuery( ann, mappings, true );
}
}
}
{
- List<SqlResultSetMapping> anns = (List<SqlResultSetMapping>) defaults.get( SqlResultSetMapping.class );
+ List<SqlResultSetMapping> anns = ( List<SqlResultSetMapping> ) defaults.get( SqlResultSetMapping.class );
if ( anns != null ) {
- for (SqlResultSetMapping ann : anns) {
+ for ( SqlResultSetMapping ann : anns ) {
QueryBinder.bindSqlResultsetMapping( ann, mappings, true );
}
}
@@ -253,7 +257,7 @@
try {
pckg = mappings.getReflectionManager().packageForName( packageName );
}
- catch (ClassNotFoundException cnf) {
+ catch ( ClassNotFoundException cnf ) {
log.warn( "Package not found or wo package-info.java: {}", packageName );
return;
}
@@ -269,10 +273,11 @@
mappings.addGenerator( idGen );
}
- bindGenericGenerators(pckg, mappings);
+ bindGenericGenerators( pckg, mappings );
bindQueries( pckg, mappings );
bindFilterDefs( pckg, mappings );
bindTypeDefs( pckg, mappings );
+ bindFetchProfiles( pckg, mappings );
BinderHelper.bindAnyMetaDefs( pckg, mappings );
}
@@ -283,7 +288,7 @@
bindGenericGenerator( defAnn, mappings );
}
if ( defsAnn != null ) {
- for (GenericGenerator def : defsAnn.value() ) {
+ for ( GenericGenerator def : defsAnn.value() ) {
bindGenericGenerator( def, mappings );
}
}
@@ -302,7 +307,7 @@
{
SqlResultSetMappings ann = annotatedElement.getAnnotation( SqlResultSetMappings.class );
if ( ann != null ) {
- for (SqlResultSetMapping current : ann.value()) {
+ for ( SqlResultSetMapping current : ann.value() ) {
QueryBinder.bindSqlResultsetMapping( current, mappings, false );
}
}
@@ -362,7 +367,7 @@
idGen = null;
}
else if ( ann instanceof TableGenerator ) {
- TableGenerator tabGen = (TableGenerator) ann;
+ TableGenerator tabGen = ( TableGenerator ) ann;
idGen.setName( tabGen.name() );
if ( useNewGeneratorMappings ) {
idGen.setIdentifierGeneratorStrategy( org.hibernate.id.enhanced.TableGenerator.class.getName() );
@@ -378,17 +383,29 @@
idGen.addParam( org.hibernate.id.enhanced.TableGenerator.TABLE_PARAM, tabGen.table() );
}
if ( !BinderHelper.isDefault( tabGen.pkColumnName() ) ) {
- idGen.addParam( org.hibernate.id.enhanced.TableGenerator.SEGMENT_COLUMN_PARAM, tabGen.pkColumnName() );
+ idGen.addParam(
+ org.hibernate.id.enhanced.TableGenerator.SEGMENT_COLUMN_PARAM, tabGen.pkColumnName()
+ );
}
if ( !BinderHelper.isDefault( tabGen.pkColumnValue() ) ) {
- idGen.addParam( org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM, tabGen.pkColumnValue() );
+ idGen.addParam(
+ org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM, tabGen.pkColumnValue()
+ );
}
if ( !BinderHelper.isDefault( tabGen.valueColumnName() ) ) {
- idGen.addParam( org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM, tabGen.valueColumnName() );
+ idGen.addParam(
+ org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM, tabGen.valueColumnName()
+ );
}
- idGen.addParam( org.hibernate.id.enhanced.TableGenerator.INCREMENT_PARAM, String.valueOf( tabGen.allocationSize() ) );
+ idGen.addParam(
+ org.hibernate.id.enhanced.TableGenerator.INCREMENT_PARAM,
+ String.valueOf( tabGen.allocationSize() )
+ );
// See comment on HHH-4884 wrt initialValue. Basically initialValue is really the stated value + 1
- idGen.addParam( org.hibernate.id.enhanced.TableGenerator.INITIAL_PARAM, String.valueOf( tabGen.initialValue() + 1 ) );
+ idGen.addParam(
+ org.hibernate.id.enhanced.TableGenerator.INITIAL_PARAM,
+ String.valueOf( tabGen.initialValue() + 1 )
+ );
if ( tabGen.uniqueConstraints() != null && tabGen.uniqueConstraints().length > 0 ) {
log.warn( "Ignoring unique constraints specified on table generator [{}]", tabGen.name() );
}
@@ -424,7 +441,7 @@
log.trace( "Add table generator with name: {}", idGen.getName() );
}
else if ( ann instanceof SequenceGenerator ) {
- SequenceGenerator seqGen = (SequenceGenerator) ann;
+ SequenceGenerator seqGen = ( SequenceGenerator ) ann;
idGen.setName( seqGen.name() );
if ( useNewGeneratorMappings ) {
idGen.setIdentifierGeneratorStrategy( SequenceStyleGenerator.class.getName() );
@@ -460,11 +477,11 @@
}
}
else if ( ann instanceof GenericGenerator ) {
- GenericGenerator genGen = (GenericGenerator) ann;
+ GenericGenerator genGen = ( GenericGenerator ) ann;
idGen.setName( genGen.name() );
idGen.setIdentifierGeneratorStrategy( genGen.strategy() );
Parameter[] params = genGen.parameters();
- for (Parameter parameter : params) {
+ for ( Parameter parameter : params ) {
idGen.addParam( parameter.name(), parameter.value() );
}
log.trace( "Add generic generator with name: {}", idGen.getName() );
@@ -476,12 +493,12 @@
}
/**
- * Bind a class having JSR175 annotations
- * The subclasses <b>have to</b> be binded after its mother class
+ * Bind a class having JSR175 annotations. Subclasses <b>have to</b> be bound after its parent class.
*
* @param clazzToProcess entity to bind as {@code XClass} instance
* @param inheritanceStatePerClass Meta data about the inheritance relationships for all mapped classes
* @param mappings Mapping meta data
+ *
* @throws MappingException in case there is an configuration error
*/
public static void bindClass(
@@ -494,21 +511,24 @@
//Queries declared in MappedSuperclass should be usable in Subclasses
if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) ) {
bindQueries( clazzToProcess, mappings );
- bindTypeDefs(clazzToProcess, mappings);
- bindFilterDefs(clazzToProcess, mappings);
+ bindTypeDefs( clazzToProcess, mappings );
+ bindFilterDefs( clazzToProcess, mappings );
}
- if( !isEntityClassType( clazzToProcess, classType ) ) {
+ if ( !isEntityClassType( clazzToProcess, classType ) ) {
return;
}
log.info( "Binding entity from annotated class: {}", clazzToProcess.getName() );
- PersistentClass superEntity = getSuperEntity(clazzToProcess, inheritanceStatePerClass, mappings, inheritanceState);
+ PersistentClass superEntity = getSuperEntity(
+ clazzToProcess, inheritanceStatePerClass, mappings, inheritanceState
+ );
bindQueries( clazzToProcess, mappings );
bindFilterDefs( clazzToProcess, mappings );
bindTypeDefs( clazzToProcess, mappings );
+ bindFetchProfiles( clazzToProcess, mappings );
BinderHelper.bindAnyMetaDefs( clazzToProcess, mappings );
String schema = "";
@@ -523,7 +543,9 @@
uniqueConstraints = TableBinder.buildUniqueConstraintHolders( tabAnn.uniqueConstraints() );
}
- Ejb3JoinColumn[] inheritanceJoinedColumns = makeInheritanceJoinColumns( clazzToProcess, mappings, inheritanceState, superEntity );
+ Ejb3JoinColumn[] inheritanceJoinedColumns = makeInheritanceJoinColumns(
+ clazzToProcess, mappings, inheritanceState, superEntity
+ );
Ejb3DiscriminatorColumn discriminatorColumn = null;
String discrimValue = null;
if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.getType() ) ) {
@@ -578,7 +600,7 @@
//Filters are not allowed on subclasses
if ( !inheritanceState.hasParents() ) {
- bindFilters(clazzToProcess, entityBinder, mappings);
+ bindFilters( clazzToProcess, entityBinder, mappings );
}
entityBinder.bindEntity();
@@ -591,14 +613,16 @@
entityBinder.bindTable(
schema, catalog, table, uniqueConstraints,
constraints, inheritanceState.hasDenormalizedTable() ?
- superEntity.getTable() :
- null
+ superEntity.getTable() :
+ null
);
}
else {
if ( clazzToProcess.isAnnotationPresent( Table.class ) ) {
- log.warn( "Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: " + clazzToProcess
- .getName() );
+ log.warn(
+ "Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: " + clazzToProcess
+ .getName()
+ );
}
}
@@ -620,7 +644,7 @@
boolean onDeleteAppropriate = false;
if ( InheritanceType.JOINED.equals( inheritanceState.getType() ) && inheritanceState.hasParents() ) {
onDeleteAppropriate = true;
- final JoinedSubclass jsc = (JoinedSubclass) persistentClass;
+ final JoinedSubclass jsc = ( JoinedSubclass ) persistentClass;
if ( persistentClass.getEntityPersisterClass() == null ) {
persistentClass.getRootClass().setEntityPersisterClass( JoinedSubclassEntityPersister.class );
}
@@ -652,7 +676,7 @@
if ( inheritanceState.hasSiblings() || !discriminatorColumn.isImplicit() ) {
//need a discriminator column
bindDiscriminatorToPersistentClass(
- (RootClass) persistentClass,
+ ( RootClass ) persistentClass,
discriminatorColumn,
entityBinder.getSecondaryTables(),
propertyHolder
@@ -695,7 +719,7 @@
mappings
);
- if (!isIdClass) {
+ if ( !isIdClass ) {
entityBinder.setWrapIdsInEmbeddedComponents( elementsToProcess.getIdPropertyCount() > 1 );
}
@@ -712,11 +736,11 @@
);
if ( !inheritanceState.hasParents() ) {
- final RootClass rootClass = (RootClass) persistentClass;
+ final RootClass rootClass = ( RootClass ) persistentClass;
mappings.addSecondPass( new CreateKeySecondPass( rootClass ) );
}
else {
- superEntity.addSubclass( (Subclass) persistentClass );
+ superEntity.addSubclass( ( Subclass ) persistentClass );
}
mappings.addClass( persistentClass );
@@ -751,7 +775,7 @@
if ( missingIdProperties.size() != 0 ) {
StringBuilder missings = new StringBuilder();
- for (String property : missingIdProperties) {
+ for ( String property : missingIdProperties ) {
missings.append( property ).append( ", " );
}
throw new AnnotationException(
@@ -771,7 +795,7 @@
* In JPA 2, there is a shortcut if the id class is the Pk of the associated class pointed to by the id
* it ought to be treated as an embedded and not a real IdClass (at least in the Hibernate's internal way
*/
- XClass classWithIdClass = inheritanceState.getClassWithIdClass(false);
+ XClass classWithIdClass = inheritanceState.getClassWithIdClass( false );
if ( classWithIdClass != null ) {
IdClass idClass = classWithIdClass.getAnnotation( IdClass.class );
XClass compositeClass = mappings.getReflectionManager().toXClass( idClass.value() );
@@ -779,8 +803,8 @@
entityBinder.getPropertyAccessType(), "id", compositeClass
);
PropertyData baseInferredData = new PropertyPreloadedData(
- entityBinder.getPropertyAccessType(), "id", classWithIdClass
- );
+ entityBinder.getPropertyAccessType(), "id", classWithIdClass
+ );
AccessType propertyAccessor = entityBinder.getPropertyAccessor( compositeClass );
//In JPA 2, there is a shortcut if the IdClass is the Pk of the associated class pointed to by the id
//it ought to be treated as an embedded and not a real IdClass (at least in the Hibernate's internal way
@@ -825,17 +849,17 @@
propertyAccessor, "_identifierMapper", compositeClass
);
Component mapper = fillComponent(
- propertyHolder,
- inferredData,
- baseInferredData,
- propertyAccessor,
- false,
- entityBinder,
- true,
- true,
- false,
- mappings,
- inheritanceStatePerClass
+ propertyHolder,
+ inferredData,
+ baseInferredData,
+ propertyAccessor,
+ false,
+ entityBinder,
+ true,
+ true,
+ false,
+ mappings,
+ inheritanceStatePerClass
);
entityBinder.setIgnoreIdAnnotations( ignoreIdAnnotations );
persistentClass.setIdentifierMapper( mapper );
@@ -847,8 +871,8 @@
inheritanceStatePerClass,
mappings
);
- if (superclass != null) {
- superclass.setDeclaredIdentifierMapper(mapper);
+ if ( superclass != null ) {
+ superclass.setDeclaredIdentifierMapper( mapper );
}
else {
//we are for sure on the entity
@@ -867,7 +891,7 @@
Iterator properties = mapper.getPropertyIterator();
while ( properties.hasNext() ) {
- idPropertiesIfIdClass.add( ( (Property) properties.next() ).getName() );
+ idPropertiesIfIdClass.add( ( ( Property ) properties.next() ).getName() );
}
return true;
}
@@ -889,7 +913,7 @@
inferredData, baseInferredData, propertyAccessor, mappings
);
final InheritanceState state = inheritanceStatePerClass.get( idPropertyOnBaseClass.getClassOrElement() );
- if (state == null) {
+ if ( state == null ) {
return false; //while it is likely a user error, let's consider it is something that might happen
}
final XClass associatedClassWithIdClass = state.getClassWithIdClass( true );
@@ -962,7 +986,7 @@
mode = SharedCacheMode.valueOf( value.toString() );
}
catch ( Exception e ) {
- log.debug(
+ log.debug(
"Unable to resolve given mode name [" + value.toString()
+ "]; using UNSPECIFIED : " + e.toString()
);
@@ -985,7 +1009,7 @@
return;
}
- if ( ! properties.containsKey( AnnotationConfiguration.DEFAULT_CACHE_CONCURRENCY_STRATEGY ) ) {
+ if ( !properties.containsKey( AnnotationConfiguration.DEFAULT_CACHE_CONCURRENCY_STRATEGY ) ) {
log.trace( "Given properties did not contain any default cache concurrency strategy setting" );
return;
}
@@ -1004,7 +1028,9 @@
private static CacheConcurrencyStrategy determineCacheConcurrencyStrategy(ExtendedMappings mappings) {
if ( DEFAULT_CACHE_CONCURRENCY_STRATEGY == null ) {
- final RegionFactory cacheRegionFactory = SettingsFactory.createRegionFactory( mappings.getConfigurationProperties(), true );
+ final RegionFactory cacheRegionFactory = SettingsFactory.createRegionFactory(
+ mappings.getConfigurationProperties(), true
+ );
DEFAULT_CACHE_CONCURRENCY_STRATEGY = CacheConcurrencyStrategy.fromAccessType( cacheRegionFactory.getDefaultAccessType() );
}
return DEFAULT_CACHE_CONCURRENCY_STRATEGY;
@@ -1071,7 +1097,7 @@
int nbrOfInhJoinedColumns = jcsAnn.value().length;
PrimaryKeyJoinColumn jcAnn;
inheritanceJoinedColumns = new Ejb3JoinColumn[nbrOfInhJoinedColumns];
- for (int colIndex = 0; colIndex < nbrOfInhJoinedColumns; colIndex++) {
+ for ( int colIndex = 0; colIndex < nbrOfInhJoinedColumns; colIndex++ ) {
jcAnn = jcsAnn.value()[colIndex];
inheritanceJoinedColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn(
jcAnn, null, superEntity.getIdentifier(),
@@ -1084,7 +1110,7 @@
inheritanceJoinedColumns = new Ejb3JoinColumn[1];
inheritanceJoinedColumns[0] = Ejb3JoinColumn.buildJoinColumn(
jcAnn, null, superEntity.getIdentifier(),
- (Map<String, Join>) null, (PropertyHolder) null, mappings
+ ( Map<String, Join> ) null, ( PropertyHolder ) null, mappings
);
}
log.trace( "Subclass joined column(s) created" );
@@ -1099,7 +1125,9 @@
}
private static PersistentClass getSuperEntity(XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, ExtendedMappings mappings, InheritanceState inheritanceState) {
- InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity( clazzToProcess, inheritanceStatePerClass );
+ InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity(
+ clazzToProcess, inheritanceStatePerClass
+ );
PersistentClass superEntity = superEntityState != null ?
mappings.getClass(
superEntityState.getClazz().getName()
@@ -1124,8 +1152,10 @@
) {
if ( AnnotatedClassType.NONE.equals( classType )
&& clazzToProcess.isAnnotationPresent( org.hibernate.annotations.Entity.class ) ) {
- log.warn( "Class annotated @org.hibernate.annotations.Entity but not javax.persistence.Entity "
- + "(most likely a user error): {}", clazzToProcess.getName() );
+ log.warn(
+ "Class annotated @org.hibernate.annotations.Entity but not javax.persistence.Entity "
+ + "(most likely a user error): {}", clazzToProcess.getName()
+ );
}
return false;
}
@@ -1144,16 +1174,17 @@
* Process the filters defined on the given class, as well as all filters defined
* on the MappedSuperclass(s) in the inheritance hierarchy
*/
+
private static void bindFilters(XClass annotatedClass, EntityBinder entityBinder,
- ExtendedMappings mappings) {
+ ExtendedMappings mappings) {
- bindFilters(annotatedClass, entityBinder);
+ bindFilters( annotatedClass, entityBinder );
XClass classToProcess = annotatedClass.getSuperclass();
- while (classToProcess != null) {
+ while ( classToProcess != null ) {
AnnotatedClassType classType = mappings.getClassType( classToProcess );
if ( AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals( classType ) ) {
- bindFilters(classToProcess, entityBinder);
+ bindFilters( classToProcess, entityBinder );
}
classToProcess = classToProcess.getSuperclass();
}
@@ -1164,7 +1195,7 @@
Filters filtersAnn = annotatedElement.getAnnotation( Filters.class );
if ( filtersAnn != null ) {
- for (Filter filter : filtersAnn.value()) {
+ for ( Filter filter : filtersAnn.value() ) {
entityBinder.addFilter( filter.name(), filter.condition() );
}
}
@@ -1182,7 +1213,7 @@
bindFilterDef( defAnn, mappings );
}
if ( defsAnn != null ) {
- for (FilterDef def : defsAnn.value()) {
+ for ( FilterDef def : defsAnn.value() ) {
bindFilterDef( def, mappings );
}
}
@@ -1190,7 +1221,7 @@
private static void bindFilterDef(FilterDef defAnn, ExtendedMappings mappings) {
Map<String, org.hibernate.type.Type> params = new HashMap<String, org.hibernate.type.Type>();
- for (ParamDef param : defAnn.parameters()) {
+ for ( ParamDef param : defAnn.parameters() ) {
params.put( param.name(), TypeFactory.heuristicType( param.type() ) );
}
FilterDefinition def = new FilterDefinition( defAnn.name(), defAnn.defaultCondition(), params );
@@ -1205,29 +1236,55 @@
bindTypeDef( defAnn, mappings );
}
if ( defsAnn != null ) {
- for (TypeDef def : defsAnn.value()) {
+ for ( TypeDef def : defsAnn.value() ) {
bindTypeDef( def, mappings );
}
}
}
+ private static void bindFetchProfiles(XAnnotatedElement annotatedElement, ExtendedMappings mappings) {
+ FetchProfile fetchProfileAnnotation = annotatedElement.getAnnotation( FetchProfile.class );
+ FetchProfiles fetchProfileAnnotations = annotatedElement.getAnnotation( FetchProfiles.class );
+ if ( fetchProfileAnnotation != null ) {
+ bindFetchProfile( fetchProfileAnnotation, mappings );
+ }
+ if ( fetchProfileAnnotations != null ) {
+ for ( FetchProfile profile : fetchProfileAnnotations.value() ) {
+ bindFetchProfile( profile, mappings );
+ }
+ }
+ }
+
+ private static void bindFetchProfile(FetchProfile fetchProfileAnnotation, ExtendedMappings mappings) {
+ for ( FetchProfile.FetchOverride fetch : fetchProfileAnnotation.fetchOverrides() ) {
+ org.hibernate.annotations.FetchMode mode = fetch.mode();
+ if ( !mode.equals( org.hibernate.annotations.FetchMode.JOIN ) ) {
+ throw new MappingException( "Only FetchMode.JOIN is currently supported" );
+ }
+
+ SecondPass sp = new VerifyFetchProfileReferenceSecondPass( fetchProfileAnnotation.name(), fetch, mappings );
+ mappings.addSecondPass( sp );
+ }
+ }
+
private static void bindTypeDef(TypeDef defAnn, ExtendedMappings mappings) {
Properties params = new Properties();
- for (Parameter param : defAnn.parameters()) {
+ for ( Parameter param : defAnn.parameters() ) {
params.setProperty( param.name(), param.value() );
}
- if (BinderHelper.isDefault(defAnn.name()) && defAnn.defaultForType().equals(void.class)) {
+ if ( BinderHelper.isDefault( defAnn.name() ) && defAnn.defaultForType().equals( void.class ) ) {
throw new AnnotationException(
"Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass " +
- defAnn.typeClass().getName());
+ defAnn.typeClass().getName()
+ );
}
- if (!BinderHelper.isDefault(defAnn.name())) {
+ if ( !BinderHelper.isDefault( defAnn.name() ) ) {
log.info( "Binding type definition: {}", defAnn.name() );
mappings.addTypeDef( defAnn.name(), defAnn.typeClass().getName(), params );
}
- if (!defAnn.defaultForType().equals(void.class)) {
+ if ( !defAnn.defaultForType().equals( void.class ) ) {
log.info( "Binding type definition: {}", defAnn.defaultForType().getName() );
mappings.addTypeDef( defAnn.defaultForType().getName(), defAnn.typeClass().getName(), params );
}
@@ -1256,14 +1313,14 @@
}
/**
- *
* @param elements List of {@code ProperyData} instances
* @param defaultAccessType The default value access strategy which has to be used in case no explicit local access
- * strategy is used
+ * strategy is used
* @param propertyContainer Metadata about a class and its properties
* @param mappings Mapping meta data
+ *
* @return the number of id properties found while iterating the elements of {@code annotatedClass} using
- * the determined access strategy, {@code false} otherwise.
+ * the determined access strategy, {@code false} otherwise.
*/
static int addElementsOfClass(
List<PropertyData> elements, AccessType defaultAccessType, PropertyContainer propertyContainer, ExtendedMappings mappings
@@ -1295,7 +1352,8 @@
int idPropertyCounter = 0;
PropertyData propertyAnnotatedElement = new PropertyInferredData(
declaringClass, property, propertyAccessor,
- mappings.getReflectionManager() );
+ mappings.getReflectionManager()
+ );
/*
* put element annotated by @Id in front
@@ -1312,7 +1370,7 @@
else {
annElts.add( propertyAnnotatedElement );
}
- if ( element.isAnnotationPresent( MapsId.class ) ) {
+ if ( element.isAnnotationPresent( MapsId.class ) ) {
mappings.addPropertyAnnotatedWithMapsId( entity, propertyAnnotatedElement );
}
@@ -1322,6 +1380,7 @@
/*
* Process annotation of a particular property
*/
+
private static void processElementAnnotations(
PropertyHolder propertyHolder, Nullability nullability,
PropertyData inferredData, HashMap<String, IdGenerator> classGenerators,
@@ -1350,7 +1409,7 @@
+ BinderHelper.getPath( propertyHolder, inferredData )
);
}
- return ;
+ return;
}
ColumnsBuilder columnsBuilder = new ColumnsBuilder(
@@ -1376,7 +1435,7 @@
}
propertyBinder.setDeclaringClass( inferredData.getDeclaringClass() );
propertyBinder.setEntityBinder( entityBinder );
- propertyBinder.setInheritanceStatePerClass(inheritanceStatePerClass);
+ propertyBinder.setInheritanceStatePerClass( inheritanceStatePerClass );
boolean isId = !entityBinder.isIgnoreIdAnnotations() &&
( property.isAnnotationPresent( Id.class )
@@ -1395,17 +1454,17 @@
+ propertyHolder.getEntityName()
);
}
- if ( ! propertyHolder.isEntity() ) {
+ if ( !propertyHolder.isEntity() ) {
throw new AnnotationException(
"Unable to define @Version on an embedded class: "
+ propertyHolder.getEntityName()
);
}
log.trace( "{} is a version property", inferredData.getPropertyName() );
- RootClass rootClass = (RootClass) propertyHolder.getPersistentClass();
+ RootClass rootClass = ( RootClass ) propertyHolder.getPersistentClass();
propertyBinder.setColumns( columns );
Property prop = propertyBinder.makePropertyValueAndBind();
- propertyBinder.getSimpleValueBinder().setVersion(true);
+ propertyBinder.getSimpleValueBinder().setVersion( true );
rootClass.setVersion( prop );
//If version is on a mapped superclass, update the mapping
@@ -1414,20 +1473,20 @@
inheritanceStatePerClass,
mappings
);
- if (superclass != null) {
- superclass.setDeclaredVersion(prop);
+ if ( superclass != null ) {
+ superclass.setDeclaredVersion( prop );
}
else {
//we know the property is on the actual entity
rootClass.setDeclaredVersion( prop );
}
- SimpleValue simpleValue = (SimpleValue) prop.getValue();
+ SimpleValue simpleValue = ( SimpleValue ) prop.getValue();
simpleValue.setNullValue( "undefined" );
rootClass.setOptimisticLockMode( Versioning.OPTIMISTIC_LOCK_VERSION );
log.trace(
"Version name: {}, unsavedValue: {}", rootClass.getVersion().getName(),
- ( (SimpleValue) rootClass.getVersion().getValue() ).getNullValue()
+ ( ( SimpleValue ) rootClass.getVersion().getValue() ).getNullValue()
);
}
else {
@@ -1439,8 +1498,10 @@
//check validity
if ( property.isAnnotationPresent( Column.class )
|| property.isAnnotationPresent( Columns.class ) ) {
- throw new AnnotationException( "@Column(s) not allowed on a @ManyToOne property: "
- + BinderHelper.getPath( propertyHolder, inferredData ) );
+ throw new AnnotationException(
+ "@Column(s) not allowed on a @ManyToOne property: "
+ + BinderHelper.getPath( propertyHolder, inferredData )
+ );
}
Cascade hibernateCascade = property.getAnnotation( Cascade.class );
@@ -1451,13 +1512,13 @@
JoinTable assocTable = propertyHolder.getJoinTable( property );
if ( assocTable != null ) {
Join join = propertyHolder.addJoin( assocTable, false );
- for (Ejb3JoinColumn joinColumn : joinColumns) {
+ for ( Ejb3JoinColumn joinColumn : joinColumns ) {
joinColumn.setSecondaryTableName( join.getTable().getName() );
}
}
final boolean mandatory = !ann.optional() || forcePersist;
bindManyToOne(
- getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist),
+ getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist ),
joinColumns,
!mandatory,
ignoreNotFound, onDeleteCascade,
@@ -1473,8 +1534,10 @@
//check validity
if ( property.isAnnotationPresent( Column.class )
|| property.isAnnotationPresent( Columns.class ) ) {
- throw new AnnotationException( "@Column(s) not allowed on a @OneToOne property: "
- + BinderHelper.getPath( propertyHolder, inferredData ) );
+ throw new AnnotationException(
+ "@Column(s) not allowed on a @OneToOne property: "
+ + BinderHelper.getPath( propertyHolder, inferredData )
+ );
}
//FIXME support a proper PKJCs
@@ -1488,14 +1551,14 @@
JoinTable assocTable = propertyHolder.getJoinTable( property );
if ( assocTable != null ) {
Join join = propertyHolder.addJoin( assocTable, false );
- for (Ejb3JoinColumn joinColumn : joinColumns) {
+ for ( Ejb3JoinColumn joinColumn : joinColumns ) {
joinColumn.setSecondaryTableName( join.getTable().getName() );
}
}
//MapsId means the columns belong to the pk => not null
final boolean mandatory = !ann.optional() || forcePersist;
bindOneToOne(
- getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist),
+ getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist ),
joinColumns,
!mandatory,
getFetchMode( ann.fetch() ),
@@ -1516,8 +1579,10 @@
//check validity
if ( property.isAnnotationPresent( Column.class )
|| property.isAnnotationPresent( Columns.class ) ) {
- throw new AnnotationException( "@Column(s) not allowed on a @Any property: "
- + BinderHelper.getPath( propertyHolder, inferredData ) );
+ throw new AnnotationException(
+ "@Column(s) not allowed on a @Any property: "
+ + BinderHelper.getPath( propertyHolder, inferredData )
+ );
}
Cascade hibernateCascade = property.getAnnotation( Cascade.class );
@@ -1526,14 +1591,22 @@
JoinTable assocTable = propertyHolder.getJoinTable( property );
if ( assocTable != null ) {
Join join = propertyHolder.addJoin( assocTable, false );
- for (Ejb3JoinColumn joinColumn : joinColumns) {
+ for ( Ejb3JoinColumn joinColumn : joinColumns ) {
joinColumn.setSecondaryTableName( join.getTable().getName() );
}
}
- bindAny( getCascadeStrategy( null, hibernateCascade, false, forcePersist), //@Any has not cascade attribute
- joinColumns, onDeleteCascade, nullability,
- propertyHolder, inferredData, entityBinder,
- isIdentifierMapper, mappings );
+ bindAny(
+ getCascadeStrategy( null, hibernateCascade, false, forcePersist ),
+ //@Any has not cascade attribute
+ joinColumns,
+ onDeleteCascade,
+ nullability,
+ propertyHolder,
+ inferredData,
+ entityBinder,
+ isIdentifierMapper,
+ mappings
+ );
}
else if ( property.isAnnotationPresent( OneToMany.class )
|| property.isAnnotationPresent( ManyToMany.class )
@@ -1549,7 +1622,7 @@
if ( property.isAnnotationPresent( OrderColumn.class ) ) {
indexColumn = IndexColumn.buildColumnFromAnnotation(
- property.getAnnotation(OrderColumn.class),
+ property.getAnnotation( OrderColumn.class ),
propertyHolder,
inferredData,
entityBinder.getSecondaryTables(),
@@ -1560,7 +1633,7 @@
//if @IndexColumn is not there, the generated IndexColumn is an implicit column and not used.
//so we can leave the legacy processing as the default
indexColumn = IndexColumn.buildColumnFromAnnotation(
- property.getAnnotation(org.hibernate.annotations.IndexColumn.class),
+ property.getAnnotation( org.hibernate.annotations.IndexColumn.class ),
propertyHolder,
inferredData,
mappings
@@ -1571,8 +1644,8 @@
property,
!indexColumn.isImplicit(),
property.isAnnotationPresent( CollectionOfElements.class )
- || property.isAnnotationPresent( org.hibernate.annotations.MapKey.class )
- // || property.isAnnotationPresent( ManyToAny.class )
+ || property.isAnnotationPresent( org.hibernate.annotations.MapKey.class )
+ // || property.isAnnotationPresent( ManyToAny.class )
);
collectionBinder.setIndexColumn( indexColumn );
MapKey mapKeyAnn = property.getAnnotation( MapKey.class );
@@ -1600,7 +1673,9 @@
Ejb3Column[] elementColumns;
//do not use "element" if you are a JPA 2 @ElementCollection only for legacy Hibernate mappings
boolean isJPA2ForValueMapping = property.isAnnotationPresent( ElementCollection.class );
- PropertyData virtualProperty = isJPA2ForValueMapping ? inferredData : new WrappedInferredData( inferredData, "element" );
+ PropertyData virtualProperty = isJPA2ForValueMapping ? inferredData : new WrappedInferredData(
+ inferredData, "element"
+ );
if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent(
Formula.class
) ) {
@@ -1643,14 +1718,14 @@
keyColumns = new Column[] { new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) ) };
}
else if ( property.isAnnotationPresent( org.hibernate.annotations.MapKey.class ) ) {
- if ( isJPA2 == null) {
+ if ( isJPA2 == null ) {
isJPA2 = Boolean.FALSE;
}
keyColumns = property.getAnnotation( org.hibernate.annotations.MapKey.class ).columns();
}
//not explicitly legacy
- if ( isJPA2 == null) {
+ if ( isJPA2 == null ) {
isJPA2 = Boolean.TRUE;
}
@@ -1677,7 +1752,8 @@
Boolean isJPA2 = null;
if ( property.isAnnotationPresent( MapKeyJoinColumns.class ) ) {
isJPA2 = Boolean.TRUE;
- final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation( MapKeyJoinColumns.class ).value();
+ final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation( MapKeyJoinColumns.class )
+ .value();
joinKeyColumns = new JoinColumn[mapKeyJoinColumns.length];
int index = 0;
for ( MapKeyJoinColumn joinColumn : mapKeyJoinColumns ) {
@@ -1685,23 +1761,32 @@
index++;
}
if ( joinKeyColumns != null ) {
- throw new AnnotationException( "@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: "
- + BinderHelper.getPath( propertyHolder, inferredData ) );
+ throw new AnnotationException(
+ "@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: "
+ + BinderHelper.getPath( propertyHolder, inferredData )
+ );
}
}
else if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
isJPA2 = Boolean.TRUE;
- joinKeyColumns = new JoinColumn[] { new MapKeyJoinColumnDelegator( property.getAnnotation( MapKeyJoinColumn.class ) ) };
+ joinKeyColumns = new JoinColumn[] {
+ new MapKeyJoinColumnDelegator(
+ property.getAnnotation(
+ MapKeyJoinColumn.class
+ )
+ )
+ };
}
else if ( property.isAnnotationPresent( org.hibernate.annotations.MapKeyManyToMany.class ) ) {
- if ( isJPA2 == null) {
+ if ( isJPA2 == null ) {
isJPA2 = Boolean.FALSE;
}
- joinKeyColumns = property.getAnnotation( org.hibernate.annotations.MapKeyManyToMany.class ).joinColumns();
+ joinKeyColumns = property.getAnnotation( org.hibernate.annotations.MapKeyManyToMany.class )
+ .joinColumns();
}
//not explicitly legacy
- if ( isJPA2 == null) {
+ if ( isJPA2 == null ) {
isJPA2 = Boolean.TRUE;
}
@@ -1732,7 +1817,7 @@
}
String mappedBy = null;
if ( oneToManyAnn != null ) {
- for (Ejb3JoinColumn column : joinColumns) {
+ for ( Ejb3JoinColumn column : joinColumns ) {
if ( column.isSecondary() ) {
throw new NotYetImplementedException( "Collections having FK in secondary table" );
}
@@ -1743,13 +1828,16 @@
mappings.getReflectionManager().toXClass( oneToManyAnn.targetEntity() )
);
collectionBinder.setCascadeStrategy(
- getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false) );
+ getCascadeStrategy(
+ oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false
+ )
+ );
collectionBinder.setOneToMany( true );
}
else if ( elementCollectionAnn != null
|| collectionOfElementsAnn != null //Hibernate legacy
) {
- for (Ejb3JoinColumn column : joinColumns) {
+ for ( Ejb3JoinColumn column : joinColumns ) {
if ( column.isSecondary() ) {
throw new NotYetImplementedException( "Collections having FK in secondary table" );
}
@@ -1770,7 +1858,11 @@
collectionBinder.setTargetEntity(
mappings.getReflectionManager().toXClass( manyToManyAnn.targetEntity() )
);
- collectionBinder.setCascadeStrategy( getCascadeStrategy( manyToManyAnn.cascade(), hibernateCascade, false, false) );
+ collectionBinder.setCascadeStrategy(
+ getCascadeStrategy(
+ manyToManyAnn.cascade(), hibernateCascade, false, false
+ )
+ );
collectionBinder.setOneToMany( false );
}
else if ( property.isAnnotationPresent( ManyToAny.class ) ) {
@@ -1778,7 +1870,7 @@
collectionBinder.setTargetEntity(
mappings.getReflectionManager().toXClass( void.class )
);
- collectionBinder.setCascadeStrategy( getCascadeStrategy( null, hibernateCascade, false, false) );
+ collectionBinder.setCascadeStrategy( getCascadeStrategy( null, hibernateCascade, false, false ) );
collectionBinder.setOneToMany( false );
}
collectionBinder.setMappedBy( mappedBy );
@@ -1795,7 +1887,7 @@
collectionBinder.setUpdatable( false );
}
if ( property.isAnnotationPresent( CollectionId.class ) ) { //do not compute the generators unless necessary
- HashMap<String, IdGenerator> localGenerators = (HashMap<String, IdGenerator>) classGenerators.clone();
+ HashMap<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone();
localGenerators.putAll( buildLocalGenerators( property, mappings ) );
collectionBinder.setLocalGenerators( localGenerators );
@@ -1815,15 +1907,17 @@
boolean isOverridden = false;
if ( isId || propertyHolder.isOrWithinEmbeddedId() || propertyHolder.isInIdClass() ) {
//the associated entity could be using an @IdClass making the overridden property a component
- final PropertyData overridingProperty = BinderHelper.getPropertyOverriddenByMapperOrMapsId( isId, propertyHolder, property.getName(), mappings );
- if (overridingProperty != null) {
+ final PropertyData overridingProperty = BinderHelper.getPropertyOverriddenByMapperOrMapsId(
+ isId, propertyHolder, property.getName(), mappings
+ );
+ if ( overridingProperty != null ) {
isOverridden = true;
final InheritanceState state = inheritanceStatePerClass.get( overridingProperty.getClassOrElement() );
- if (state != null) {
+ if ( state != null ) {
isComponent = isComponent || state.hasIdClassOrEmbeddedId();
}
//Get the new column
- columns = columnsBuilder.overrideColumnFromMapperOrMapsIdProperty(isId);
+ columns = columnsBuilder.overrideColumnFromMapperOrMapsIdProperty( isId );
}
}
@@ -1835,7 +1929,7 @@
if ( isComponent ) {
String referencedEntityName = null;
- if (isOverridden) {
+ if ( isOverridden ) {
final PropertyData mapsIdProperty = BinderHelper.getPropertyOverriddenByMapperOrMapsId(
isId, propertyHolder, property.getName(), mappings
);
@@ -1853,7 +1947,7 @@
isId,
inheritanceStatePerClass,
referencedEntityName,
- isOverridden ? (Ejb3JoinColumn[]) columns : null
+ isOverridden ? ( Ejb3JoinColumn[] ) columns : null
);
}
else {
@@ -1868,14 +1962,14 @@
//implicit type will check basic types and Serializable classes
if ( isId || ( !optional && nullability != Nullability.FORCED_NULL ) ) {
//force columns to not null
- for (Ejb3Column col : columns) {
+ for ( Ejb3Column col : columns ) {
col.forceNotNull();
}
}
propertyBinder.setLazy( lazy );
propertyBinder.setColumns( columns );
- if (isOverridden) {
+ if ( isOverridden ) {
final PropertyData mapsIdProperty = BinderHelper.getPropertyOverriddenByMapperOrMapsId(
isId, propertyHolder, property.getName(), mappings
);
@@ -1885,27 +1979,27 @@
propertyBinder.makePropertyValueAndBind();
}
- if (isOverridden) {
- final PropertyData mapsIdProperty = BinderHelper.getPropertyOverriddenByMapperOrMapsId(
- isId, propertyHolder, property.getName(), mappings
- );
- Map<String, IdGenerator> localGenerators = (HashMap<String, IdGenerator>) classGenerators.clone();
- final IdGenerator foreignGenerator = new IdGenerator();
- foreignGenerator.setIdentifierGeneratorStrategy( "assigned" );
- foreignGenerator.setName( "Hibernate-local--foreign generator" );
- foreignGenerator.setIdentifierGeneratorStrategy( "foreign" );
- foreignGenerator.addParam( "property", mapsIdProperty.getPropertyName() );
- localGenerators.put( foreignGenerator.getName(), foreignGenerator );
+ if ( isOverridden ) {
+ final PropertyData mapsIdProperty = BinderHelper.getPropertyOverriddenByMapperOrMapsId(
+ isId, propertyHolder, property.getName(), mappings
+ );
+ Map<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone();
+ final IdGenerator foreignGenerator = new IdGenerator();
+ foreignGenerator.setIdentifierGeneratorStrategy( "assigned" );
+ foreignGenerator.setName( "Hibernate-local--foreign generator" );
+ foreignGenerator.setIdentifierGeneratorStrategy( "foreign" );
+ foreignGenerator.addParam( "property", mapsIdProperty.getPropertyName() );
+ localGenerators.put( foreignGenerator.getName(), foreignGenerator );
- BinderHelper.makeIdGenerator(
- (SimpleValue) propertyBinder.getValue(),
- foreignGenerator.getIdentifierGeneratorStrategy(),
- foreignGenerator.getName(),
- mappings,
- localGenerators
- );
- }
- if (isId) {
+ BinderHelper.makeIdGenerator(
+ ( SimpleValue ) propertyBinder.getValue(),
+ foreignGenerator.getIdentifierGeneratorStrategy(),
+ foreignGenerator.getName(),
+ mappings,
+ localGenerators
+ );
+ }
+ if ( isId ) {
//components and regular basic types create SimpleValue objects
final SimpleValue value = ( SimpleValue ) propertyBinder.getValue();
if ( !isOverridden ) {
@@ -1927,13 +2021,13 @@
if ( index != null ) {
if ( joinColumns != null ) {
- for (Ejb3Column column : joinColumns) {
+ for ( Ejb3Column column : joinColumns ) {
column.addIndex( index, inSecondPass );
}
}
else {
if ( columns != null ) {
- for (Ejb3Column column : columns) {
+ for ( Ejb3Column column : columns ) {
column.addIndex( index, inSecondPass );
}
}
@@ -1943,12 +2037,12 @@
NaturalId naturalIdAnn = property.getAnnotation( NaturalId.class );
if ( naturalIdAnn != null ) {
if ( joinColumns != null ) {
- for (Ejb3Column column : joinColumns) {
+ for ( Ejb3Column column : joinColumns ) {
column.addUniqueKey( "_UniqueKey", inSecondPass );
}
}
else {
- for (Ejb3Column column : columns) {
+ for ( Ejb3Column column : columns ) {
column.addUniqueKey( "_UniqueKey", inSecondPass );
}
}
@@ -1971,7 +2065,7 @@
XClass returnedClass = inferredData.getClassOrElement();
XProperty property = inferredData.getProperty();
//clone classGenerator and override with local values
- HashMap<String, IdGenerator> localGenerators = (HashMap<String, IdGenerator>) classGenerators.clone();
+ HashMap<String, IdGenerator> localGenerators = ( HashMap<String, IdGenerator> ) classGenerators.clone();
localGenerators.putAll( buildLocalGenerators( property, mappings ) );
//manage composite related metadata
@@ -1986,7 +2080,9 @@
String generatorName = generatedValue != null ?
generatedValue.generator() :
BinderHelper.ANNOTATION_STRING_DEFAULT;
- if ( isComponent ) generatorType = "assigned"; //a component must not have any generator
+ if ( isComponent ) {
+ generatorType = "assigned";
+ } //a component must not have any generator
BinderHelper.makeIdGenerator( idValue, generatorType, generatorName, mappings, localGenerators );
log.trace(
@@ -1995,6 +2091,7 @@
}
//TODO move that to collection binder?
+
private static void bindJoinedTableAssociation(
XProperty property, ExtendedMappings mappings, EntityBinder entityBinder,
CollectionBinder collectionBinder, PropertyHolder propertyHolder, PropertyData inferredData,
@@ -2016,7 +2113,7 @@
final JoinColumn[] inverseJoins;
//JPA 2 has priority
- if (collectionTable != null) {
+ if ( collectionTable != null ) {
catalog = collectionTable.catalog();
schema = collectionTable.schema();
tableName = collectionTable.name();
@@ -2035,9 +2132,15 @@
collectionBinder.setExplicitAssociationTable( true );
- if ( !BinderHelper.isDefault( schema ) ) associationTableBinder.setSchema( schema );
- if ( !BinderHelper.isDefault( catalog ) ) associationTableBinder.setCatalog( catalog );
- if ( !BinderHelper.isDefault( tableName ) ) associationTableBinder.setName( tableName );
+ if ( !BinderHelper.isDefault( schema ) ) {
+ associationTableBinder.setSchema( schema );
+ }
+ if ( !BinderHelper.isDefault( catalog ) ) {
+ associationTableBinder.setCatalog( catalog );
+ }
+ if ( !BinderHelper.isDefault( tableName ) ) {
+ associationTableBinder.setName( tableName );
+ }
associationTableBinder.setUniqueConstraints( uniqueConstraints );
//set check constaint in the second pass
@@ -2081,7 +2184,8 @@
comp,
referencedEntityName,
columns,
- mappings);
+ mappings
+ );
mappings.addSecondPass( sp );
}
else {
@@ -2091,18 +2195,21 @@
false, mappings, inheritanceStatePerClass
);
}
- if (isId) {
+ if ( isId ) {
comp.setKey( true );
if ( propertyHolder.getPersistentClass().getIdentifier() != null ) {
throw new AnnotationException(
comp.getComponentClassName()
- + " must not have @Id properties when used as an @EmbeddedId: "
- + BinderHelper.getPath( propertyHolder, inferredData ) );
+ + " must not have @Id properties when used as an @EmbeddedId: "
+ + BinderHelper.getPath( propertyHolder, inferredData )
+ );
}
if ( referencedEntityName == null && comp.getPropertySpan() == 0 ) {
- throw new AnnotationException( comp.getComponentClassName()
- + " has no persistent id property: "
- + BinderHelper.getPath( propertyHolder, inferredData ) );
+ throw new AnnotationException(
+ comp.getComponentClassName()
+ + " has no persistent id property: "
+ + BinderHelper.getPath( propertyHolder, inferredData )
+ );
}
}
XProperty property = inferredData.getProperty();
@@ -2124,24 +2231,26 @@
public static Component fillComponent(
PropertyHolder propertyHolder, PropertyData inferredData,
- AccessType propertyAccessor, boolean isNullable,
+ AccessType propertyAccessor, boolean isNullable,
EntityBinder entityBinder,
boolean isComponentEmbedded, boolean isIdentifierMapper, boolean inSecondPass,
ExtendedMappings mappings, Map<XClass, InheritanceState> inheritanceStatePerClass
) {
- return fillComponent(propertyHolder, inferredData, null, propertyAccessor,
- isNullable, entityBinder, isComponentEmbedded, isIdentifierMapper, inSecondPass, mappings,
- inheritanceStatePerClass);
+ return fillComponent(
+ propertyHolder, inferredData, null, propertyAccessor,
+ isNullable, entityBinder, isComponentEmbedded, isIdentifierMapper, inSecondPass, mappings,
+ inheritanceStatePerClass
+ );
}
public static Component fillComponent(
- PropertyHolder propertyHolder, PropertyData inferredData,
- PropertyData baseInferredData, //base inferred data correspond to the entity reproducing inferredData's properties (ie IdClass)
- AccessType propertyAccessor, boolean isNullable, EntityBinder entityBinder,
- boolean isComponentEmbedded, boolean isIdentifierMapper, boolean inSecondPass, ExtendedMappings mappings,
- Map<XClass, InheritanceState> inheritanceStatePerClass
- ) {
+ PropertyHolder propertyHolder, PropertyData inferredData,
+ PropertyData baseInferredData, //base inferred data correspond to the entity reproducing inferredData's properties (ie IdClass)
+ AccessType propertyAccessor, boolean isNullable, EntityBinder entityBinder,
+ boolean isComponentEmbedded, boolean isIdentifierMapper, boolean inSecondPass, ExtendedMappings mappings,
+ Map<XClass, InheritanceState> inheritanceStatePerClass
+ ) {
/**
* inSecondPass can only be used to apply right away the second pass of a composite-element
@@ -2163,21 +2272,21 @@
List<PropertyData> baseClassElements = null;
Map<String, PropertyData> orderedBaseClassElements = new HashMap<String, PropertyData>();
XClass baseReturnedClassOrElement;
- if(baseInferredData != null) {
+ if ( baseInferredData != null ) {
baseClassElements = new ArrayList<PropertyData>();
baseReturnedClassOrElement = baseInferredData.getClassOrElement();
- bindTypeDefs(baseReturnedClassOrElement, mappings);
+ bindTypeDefs( baseReturnedClassOrElement, mappings );
PropertyContainer propContainer = new PropertyContainer( baseReturnedClassOrElement, xClassProcessed );
addElementsOfClass( baseClassElements, propertyAccessor, propContainer, mappings );
- for (PropertyData element : baseClassElements) {
+ for ( PropertyData element : baseClassElements ) {
orderedBaseClassElements.put( element.getPropertyName(), element );
}
}
//embeddable elements can have type defs
- bindTypeDefs(returnedClassOrElement, mappings);
+ bindTypeDefs( returnedClassOrElement, mappings );
PropertyContainer propContainer = new PropertyContainer( returnedClassOrElement, xClassProcessed );
- addElementsOfClass( classElements, propertyAccessor, propContainer, mappings);
+ addElementsOfClass( classElements, propertyAccessor, propContainer, mappings );
//add elements of the embeddable superclass
XClass superClass = xClassProcessed.getSuperclass();
@@ -2194,17 +2303,18 @@
final PropertyData idClassPropertyData = classElements.get( i );
final PropertyData entityPropertyData = orderedBaseClassElements.get( idClassPropertyData.getPropertyName() );
if ( propertyHolder.isInIdClass() ) {
- if (entityPropertyData == null) {
- throw new AnnotationException (
+ if ( entityPropertyData == null ) {
+ throw new AnnotationException(
"Property of @IdClass not found in entity "
+ baseInferredData.getPropertyClass().getName() + ": "
- + idClassPropertyData.getPropertyName()
+ + idClassPropertyData.getPropertyName()
);
}
final boolean hasXToOneAnnotation = entityPropertyData.getProperty()
.isAnnotationPresent( ManyToOne.class )
|| entityPropertyData.getProperty().isAnnotationPresent( OneToOne.class );
- final boolean isOfDifferentType = ! entityPropertyData.getClassOrElement().equals( idClassPropertyData.getClassOrElement() );
+ final boolean isOfDifferentType = !entityPropertyData.getClassOrElement()
+ .equals( idClassPropertyData.getClassOrElement() );
if ( hasXToOneAnnotation && isOfDifferentType ) {
//don't replace here as we need to use the actual original return type
//the annotation overriding will be dealt with by a mechanism similar to @MapsId
@@ -2219,28 +2329,36 @@
}
}
}
- for (PropertyData propertyAnnotatedElement : classElements) {
+ for ( PropertyData propertyAnnotatedElement : classElements ) {
processElementAnnotations(
subHolder, isNullable ?
- Nullability.NO_CONSTRAINT :
- Nullability.FORCED_NOT_NULL,
+ Nullability.NO_CONSTRAINT :
+ Nullability.FORCED_NOT_NULL,
propertyAnnotatedElement,
new HashMap<String, IdGenerator>(), entityBinder, isIdentifierMapper, isComponentEmbedded,
inSecondPass, mappings, inheritanceStatePerClass
);
-
+
XProperty property = propertyAnnotatedElement.getProperty();
- if(property.isAnnotationPresent(GeneratedValue.class) &&
- property.isAnnotationPresent(Id.class) ) {
- //clone classGenerator and override with local values
- Map<String, IdGenerator> localGenerators = new HashMap<String, IdGenerator>();
- localGenerators.putAll( buildLocalGenerators( property, mappings ) );
+ if ( property.isAnnotationPresent( GeneratedValue.class ) &&
+ property.isAnnotationPresent( Id.class ) ) {
+ //clone classGenerator and override with local values
+ Map<String, IdGenerator> localGenerators = new HashMap<String, IdGenerator>();
+ localGenerators.putAll( buildLocalGenerators( property, mappings ) );
- GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
- String generatorType = generatedValue != null ? generatorType( generatedValue.strategy(), mappings ) : "assigned";
- String generator = generatedValue != null ? generatedValue.generator() : BinderHelper.ANNOTATION_STRING_DEFAULT;
-
- BinderHelper.makeIdGenerator( (SimpleValue) comp.getProperty(property.getName()).getValue(), generatorType, generator, mappings, localGenerators);
+ GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
+ String generatorType = generatedValue != null ? generatorType(
+ generatedValue.strategy(), mappings
+ ) : "assigned";
+ String generator = generatedValue != null ? generatedValue.generator() : BinderHelper.ANNOTATION_STRING_DEFAULT;
+
+ BinderHelper.makeIdGenerator(
+ ( SimpleValue ) comp.getProperty( property.getName() ).getValue(),
+ generatorType,
+ generator,
+ mappings,
+ localGenerators
+ );
}
}
@@ -2263,14 +2381,14 @@
return comp;
}
- private static void bindIdClass(
- String generatorType, String generatorName, PropertyData inferredData,
- PropertyData baseInferredData, Ejb3Column[] columns, PropertyHolder propertyHolder,
- boolean isComposite,
- AccessType propertyAccessor, EntityBinder entityBinder, boolean isEmbedded,
- boolean isIdentifierMapper, ExtendedMappings mappings,
- Map<XClass, InheritanceState> inheritanceStatePerClass
- ) {
+ private static void bindIdClass(
+ String generatorType, String generatorName, PropertyData inferredData,
+ PropertyData baseInferredData, Ejb3Column[] columns, PropertyHolder propertyHolder,
+ boolean isComposite,
+ AccessType propertyAccessor, EntityBinder entityBinder, boolean isEmbedded,
+ boolean isIdentifierMapper, ExtendedMappings mappings,
+ Map<XClass, InheritanceState> inheritanceStatePerClass
+ ) {
/*
* Fill simple value and property since and Id is a property
@@ -2282,7 +2400,7 @@
+ propertyHolder.getEntityName()
);
}
- RootClass rootClass = (RootClass) persistentClass;
+ RootClass rootClass = ( RootClass ) persistentClass;
String persistentClassName = rootClass.getClassName();
SimpleValue id;
final String propertyName = inferredData.getPropertyName();
@@ -2292,7 +2410,7 @@
propertyHolder, inferredData, baseInferredData, propertyAccessor,
false, entityBinder, isEmbedded, isIdentifierMapper, false, mappings, inheritanceStatePerClass
);
- Component componentId = (Component) id;
+ Component componentId = ( Component ) id;
componentId.setKey( true );
if ( rootClass.getIdentifier() != null ) {
throw new AnnotationException( componentId.getComponentClassName() + " must not have @Id properties when used as an @EmbeddedId" );
@@ -2307,7 +2425,7 @@
else {
//TODO I think this branch is never used. Remove.
- for (Ejb3Column column : columns) {
+ for ( Ejb3Column column : columns ) {
column.forceNotNull(); //this is an id
}
SimpleValueBinder value = new SimpleValueBinder();
@@ -2338,8 +2456,8 @@
inheritanceStatePerClass,
mappings
);
- if (superclass != null) {
- superclass.setDeclaredIdentifierProperty(prop);
+ if ( superclass != null ) {
+ superclass.setDeclaredIdentifierProperty( prop );
}
else {
//we know the property is on the actual entity
@@ -2351,7 +2469,9 @@
private static PropertyData getUniqueIdPropertyFromBaseClass(PropertyData inferredData, PropertyData baseInferredData, AccessType propertyAccessor, ExtendedMappings mappings) {
List<PropertyData> baseClassElements = new ArrayList<PropertyData>();
XClass baseReturnedClassOrElement = baseInferredData.getClassOrElement();
- PropertyContainer propContainer = new PropertyContainer( baseReturnedClassOrElement, inferredData.getPropertyClass() );
+ PropertyContainer propContainer = new PropertyContainer(
+ baseReturnedClassOrElement, inferredData.getPropertyClass()
+ );
addElementsOfClass( baseClassElements, propertyAccessor, propContainer, mappings );
//Id properties are on top and there is only one
final PropertyData idPropertyOnBaseClass = baseClassElements.get( 0 );
@@ -2359,9 +2479,11 @@
}
private static void setupComponentTuplizer(XProperty property, Component component) {
- if ( property == null ) return;
+ if ( property == null ) {
+ return;
+ }
if ( property.isAnnotationPresent( Tuplizers.class ) ) {
- for (Tuplizer tuplizer : property.getAnnotation( Tuplizers.class ).value()) {
+ for ( Tuplizer tuplizer : property.getAnnotation( Tuplizers.class ).value() ) {
EntityMode mode = EntityMode.parse( tuplizer.entityMode() );
component.addTuplizer( mode, tuplizer.impl().getName() );
}
@@ -2388,7 +2510,7 @@
if ( unique ) {
value.markAsLogicalOneToOne();
}
- value.setReferencedEntityName( ToOneBinder.getReferenceEntityName(inferredData, targetEntity, mappings) );
+ value.setReferencedEntityName( ToOneBinder.getReferenceEntityName( inferredData, targetEntity, mappings ) );
final XProperty property = inferredData.getProperty();
defineFetchingStrategy( value, property );
//value.setFetchMode( fetchMode );
@@ -2396,13 +2518,13 @@
value.setCascadeDeleteEnabled( cascadeOnDelete );
//value.setLazy( fetchMode != FetchMode.JOIN );
if ( !optional ) {
- for (Ejb3JoinColumn column : columns) {
+ for ( Ejb3JoinColumn column : columns ) {
column.setNullable( false );
}
}
if ( property.isAnnotationPresent( MapsId.class ) ) {
//read only
- for (Ejb3JoinColumn column : columns) {
+ for ( Ejb3JoinColumn column : columns ) {
column.setInsertable( false );
column.setUpdatable( false );
}
@@ -2415,7 +2537,9 @@
String fkName = fk != null ?
fk.name() :
"";
- if ( !BinderHelper.isDefault( fkName ) ) value.setForeignKeyName( fkName );
+ if ( !BinderHelper.isDefault( fkName ) ) {
+ value.setForeignKeyName( fkName );
+ }
String path = propertyHolder.getPath() + "." + propertyName;
FkSecondPass secondPass = new ToOneFkSecondPass(
@@ -2531,15 +2655,15 @@
Iterator idColumns = identifier.getColumnIterator();
List<String> idColumnNames = new ArrayList<String>();
org.hibernate.mapping.Column currentColumn;
- if ( identifier.getColumnSpan() != joinColumns.length ) {
+ if ( identifier.getColumnSpan() != joinColumns.length ) {
mapToPK = false;
}
else {
while ( idColumns.hasNext() ) {
- currentColumn = (org.hibernate.mapping.Column) idColumns.next();
+ currentColumn = ( org.hibernate.mapping.Column ) idColumns.next();
idColumnNames.add( currentColumn.getName() );
}
- for (Ejb3JoinColumn col : joinColumns) {
+ for ( Ejb3JoinColumn col : joinColumns ) {
if ( !idColumnNames.contains( col.getMappingColumn().getName() ) ) {
mapToPK = false;
break;
@@ -2583,13 +2707,18 @@
PropertyHolder propertyHolder, PropertyData inferredData, EntityBinder entityBinder,
boolean isIdentifierMapper, ExtendedMappings mappings
) {
- org.hibernate.annotations.Any anyAnn = inferredData.getProperty().getAnnotation( org.hibernate.annotations.Any.class );
+ org.hibernate.annotations.Any anyAnn = inferredData.getProperty()
+ .getAnnotation( org.hibernate.annotations.Any.class );
if ( anyAnn == null ) {
- throw new AssertionFailure( "Missing @Any annotation: "
- + BinderHelper.getPath( propertyHolder, inferredData ) );
+ throw new AssertionFailure(
+ "Missing @Any annotation: "
+ + BinderHelper.getPath( propertyHolder, inferredData )
+ );
}
- Any value = BinderHelper.buildAnyValue( anyAnn.metaDef(), columns, anyAnn.metaColumn(), inferredData,
- cascadeOnDelete, nullability, propertyHolder, entityBinder, anyAnn.optional(), mappings );
+ Any value = BinderHelper.buildAnyValue(
+ anyAnn.metaDef(), columns, anyAnn.metaColumn(), inferredData,
+ cascadeOnDelete, nullability, propertyHolder, entityBinder, anyAnn.optional(), mappings
+ );
PropertyBinder binder = new PropertyBinder();
binder.setName( inferredData.getPropertyName() );
@@ -2636,7 +2765,7 @@
private static EnumSet<CascadeType> convertToHibernateCascadeType(javax.persistence.CascadeType[] ejbCascades) {
EnumSet<CascadeType> hibernateCascadeSet = EnumSet.noneOf( CascadeType.class );
if ( ejbCascades != null && ejbCascades.length > 0 ) {
- for (javax.persistence.CascadeType cascade : ejbCascades) {
+ for ( javax.persistence.CascadeType cascade : ejbCascades ) {
switch ( cascade ) {
case ALL:
hibernateCascadeSet.add( CascadeType.ALL );
@@ -2664,8 +2793,8 @@
}
private static String getCascadeStrategy(
- javax.persistence.CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation,
- boolean orphanRemoval, boolean forcePersist) {
+ javax.persistence.CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation,
+ boolean orphanRemoval, boolean forcePersist) {
EnumSet<CascadeType> hibernateCascadeSet = convertToHibernateCascadeType( ejbCascades );
CascadeType[] hibernateCascades = hibernateCascadeAnnotation == null ?
null :
@@ -2676,11 +2805,11 @@
}
if ( orphanRemoval ) {
- hibernateCascadeSet.add(CascadeType.DELETE_ORPHAN);
- hibernateCascadeSet.add(CascadeType.REMOVE);
+ hibernateCascadeSet.add( CascadeType.DELETE_ORPHAN );
+ hibernateCascadeSet.add( CascadeType.REMOVE );
}
- if (forcePersist) {
- hibernateCascadeSet.add(CascadeType.PERSIST);
+ if ( forcePersist ) {
+ hibernateCascadeSet.add( CascadeType.PERSIST );
}
StringBuilder cascade = new StringBuilder();
@@ -2765,6 +2894,7 @@
* inheritance status of a class.
*
* @param orderedClasses Order list of all annotated entities and their mapped superclasses
+ *
* @return A map of {@code InheritanceState}s keyed against their {@code XClass}.
*/
public static Map<XClass, InheritanceState> buildInheritanceStates(
@@ -2774,20 +2904,24 @@
Map<XClass, InheritanceState> inheritanceStatePerClass = new HashMap<XClass, InheritanceState>(
orderedClasses.size()
);
- for (XClass clazz : orderedClasses) {
+ for ( XClass clazz : orderedClasses ) {
InheritanceState superclassState = InheritanceState.getSuperclassInheritanceState(
- clazz, inheritanceStatePerClass );
+ clazz, inheritanceStatePerClass
+ );
InheritanceState state = new InheritanceState( clazz, inheritanceStatePerClass, mappings );
if ( superclassState != null ) {
//the classes are ordered thus preventing an NPE
//FIXME if an entity has subclasses annotated @MappedSperclass wo sub @Entity this is wrong
superclassState.setHasSiblings( true );
InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity(
- clazz, inheritanceStatePerClass );
+ clazz, inheritanceStatePerClass
+ );
state.setHasParents( superEntityState != null );
- final boolean nonDefault = state.getType() != null && !InheritanceType.SINGLE_TABLE.equals( state.getType() );
+ final boolean nonDefault = state.getType() != null && !InheritanceType.SINGLE_TABLE
+ .equals( state.getType() );
if ( superclassState.getType() != null ) {
- final boolean mixingStrategy = state.getType() != null && !state.getType().equals( superclassState.getType() );
+ final boolean mixingStrategy = state.getType() != null && !state.getType()
+ .equals( superclassState.getType() );
if ( nonDefault && mixingStrategy ) {
log.warn(
"Mixing inheritance strategy in a entity hierarchy is not allowed, ignoring sub strategy in: {}",
@@ -2802,8 +2936,7 @@
return inheritanceStatePerClass;
}
- private static boolean hasAnnotationsOnIdClass(XClass idClass)
- {
+ private static boolean hasAnnotationsOnIdClass(XClass idClass) {
// if(idClass.getAnnotation(Embeddable.class) != null)
// return true;
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-03-04 18:15:19 UTC (rev 18923)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -33,7 +33,9 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -55,10 +57,10 @@
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
-import org.xml.sax.ErrorHandler;
import org.hibernate.AnnotationException;
import org.hibernate.DuplicateMappingException;
@@ -68,12 +70,12 @@
import org.hibernate.SessionFactory;
import org.hibernate.annotations.AnyMetaDef;
import org.hibernate.annotations.Cache;
+import org.hibernate.annotations.common.AssertionFailure;
import org.hibernate.annotations.common.reflection.MetadataProvider;
import org.hibernate.annotations.common.reflection.MetadataProviderInjector;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
-import org.hibernate.annotations.common.AssertionFailure;
import org.hibernate.cfg.annotations.Version;
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
import org.hibernate.cfg.beanvalidation.BeanValidationActivator;
@@ -84,15 +86,16 @@
import org.hibernate.event.PreInsertEventListener;
import org.hibernate.event.PreUpdateEventListener;
import org.hibernate.mapping.Column;
+import org.hibernate.mapping.FetchProfile;
import org.hibernate.mapping.IdGenerator;
import org.hibernate.mapping.Join;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.UniqueKey;
+import org.hibernate.util.CollectionHelper;
import org.hibernate.util.JoinedIterator;
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
-import org.hibernate.util.CollectionHelper;
/**
* Similar to the {@link Configuration} object but handles EJB3 and Hibernate
@@ -132,8 +135,9 @@
Version.touch(); //touch version
}
- public static final String ARTEFACT = "hibernate.mapping.precedence";
- public static final String DEFAULT_PRECEDENCE = "hbm, class";
+ public static final String ARTEFACT_PROCESSING_ORDER = "hibernate.mapping.precedence";
+ public static final ConfigurationArtefactType[] DEFAULT_ARTEFACT_PROCESSING_ORDER =
+ new ConfigurationArtefactType[] { ConfigurationArtefactType.HBM, ConfigurationArtefactType.CLASS };
private Map<String, IdGenerator> namedGenerators;
private Map<String, Map<String, Join>> joins;
@@ -152,13 +156,13 @@
private Map<String, Document> hbmEntities;
private List<CacheHolder> caches;
private List<Document> hbmDocuments; //user ordering matters, hence the list
- private String precedence = null;
+ private List<ConfigurationArtefactType> configurationArtefactPrecedence;
private boolean inSecondPass = false;
private transient ReflectionManager reflectionManager;
private boolean isDefaultProcessed = false;
private boolean isValidatorNotPresentLogged;
- private Map<XClass,Map<String,PropertyData>> propertiesAnnotatedWithMapsId;
- private Map<XClass,Map<String,PropertyData>> propertiesAnnotatedWithIdAndToOne;
+ private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithMapsId;
+ private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithIdAndToOne;
public AnnotationConfiguration() {
super();
@@ -173,9 +177,10 @@
* ordered list.
*
* @param original The list of all entities annotated with {@code @Entity} or {@code @MappedSuperclass}
+ *
* @return Ordered list of entities including superclasses for entities which have any. Class hierachies are
- * listed bottom up (starting from the top level base class). There is no indication in the list when a new class
- * (hierarchy) starts.
+ * listed bottom up (starting from the top level base class). There is no indication in the list when a new class
+ * (hierarchy) starts.
*/
protected List<XClass> orderAndFillHierarchy(List<XClass> original) {
List<XClass> copy = new ArrayList<XClass>( original );
@@ -226,6 +231,8 @@
* @param persistentClass the mapped class
*
* @return the configuration object
+ *
+ * @throws MappingException in case there is a configuration error for the specified class
*/
public AnnotationConfiguration addAnnotatedClass(Class persistentClass) throws MappingException {
XClass persistentXClass = reflectionManager.toXClass( persistentClass );
@@ -240,11 +247,13 @@
}
/**
- * Read package level metadata
+ * Read package level metadata.
*
* @param packageName java package name
*
* @return the configuration object
+ *
+ * @throws MappingException in case there is an error in the mapping data
*/
public AnnotationConfiguration addPackage(String packageName) throws MappingException {
log.info( "Mapping package {}", packageName );
@@ -297,11 +306,11 @@
namingStrategy = EJB3NamingStrategy.INSTANCE;
setEntityResolver( new EJB3DTDEntityResolver() );
anyMetaDefs = new HashMap<String, AnyMetaDef>();
- propertiesAnnotatedWithMapsId = new HashMap<XClass, Map<String,PropertyData>>();
- propertiesAnnotatedWithIdAndToOne = new HashMap<XClass, Map<String,PropertyData>>();
+ propertiesAnnotatedWithMapsId = new HashMap<XClass, Map<String, PropertyData>>();
+ propertiesAnnotatedWithIdAndToOne = new HashMap<XClass, Map<String, PropertyData>>();
reflectionManager = new JavaReflectionManager();
( ( MetadataProviderInjector ) reflectionManager ).setMetadataProvider( new JPAMetadataProvider() );
-
+ configurationArtefactPrecedence = Collections.emptyList();
}
@Override
@@ -327,7 +336,7 @@
if ( !isDefaultProcessed ) {
//use global delimiters if orm.xml declare it
final Object isDelimited = reflectionManager.getDefaults().get( "delimited-identifier" );
- if (isDelimited != null && isDelimited == Boolean.TRUE) {
+ if ( isDelimited != null && isDelimited == Boolean.TRUE ) {
getProperties().put( Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true" );
}
@@ -336,21 +345,19 @@
}
//process entities
- if ( precedence == null ) {
- precedence = getProperties().getProperty( ARTEFACT );
+ if ( configurationArtefactPrecedence.isEmpty()
+ && StringHelper.isNotEmpty( getProperties().getProperty( ARTEFACT_PROCESSING_ORDER ) ) ) {
+ configurationArtefactPrecedence = parsePrecedence( getProperties().getProperty( ARTEFACT_PROCESSING_ORDER ) );
}
- if ( precedence == null ) {
- precedence = DEFAULT_PRECEDENCE;
+ if ( configurationArtefactPrecedence.isEmpty() ) {
+ configurationArtefactPrecedence = Arrays.asList( DEFAULT_ARTEFACT_PROCESSING_ORDER );
}
- StringTokenizer precedences = new StringTokenizer( precedence, ",; ", false );
- if ( !precedences.hasMoreElements() ) {
- throw new MappingException( ARTEFACT + " cannot be empty: " + precedence );
+ configurationArtefactPrecedence = Collections.unmodifiableList( configurationArtefactPrecedence );
+
+ for ( ConfigurationArtefactType p : configurationArtefactPrecedence ) {
+ removeConflictedArtifact( p );
+ processArtifactsOfType( p );
}
- while ( precedences.hasMoreElements() ) {
- String artifact = ( String ) precedences.nextElement();
- removeConflictedArtifact( artifact );
- processArtifactsOfType( artifact );
- }
int cacheNbr = caches.size();
for ( int index = 0; index < cacheNbr; index++ ) {
@@ -381,11 +388,9 @@
throw ( RuntimeException ) e.getCause();
}
- Iterator<Map.Entry<Table,List<UniqueConstraintHolder>>> tables = uniqueConstraintHoldersByTable.entrySet().iterator();
- while ( tables.hasNext() ) {
- final Map.Entry<Table,List<UniqueConstraintHolder>> entry = tables.next();
- final Table table = entry.getKey();
- final List<UniqueConstraintHolder> uniqueConstraints = entry.getValue();
+ for ( Map.Entry<Table, List<UniqueConstraintHolder>> tableListEntry : uniqueConstraintHoldersByTable.entrySet() ) {
+ final Table table = tableListEntry.getKey();
+ final List<UniqueConstraintHolder> uniqueConstraints = tableListEntry.getValue();
int uniqueIndexPerTable = 0;
for ( UniqueConstraintHolder holder : uniqueConstraints ) {
uniqueIndexPerTable++;
@@ -607,8 +612,8 @@
}
}
- private void processArtifactsOfType(String artifact) {
- if ( "hbm".equalsIgnoreCase( artifact ) ) {
+ private void processArtifactsOfType(ConfigurationArtefactType p) {
+ if ( ConfigurationArtefactType.HBM.equals( p ) ) {
log.debug( "Process hbm files" );
for ( Document document : hbmDocuments ) {
super.add( document );
@@ -616,7 +621,7 @@
hbmDocuments.clear();
hbmEntities.clear();
}
- else if ( "class".equalsIgnoreCase( artifact ) ) {
+ else if ( ConfigurationArtefactType.CLASS.equals( p ) ) {
log.debug( "Process annotated classes" );
//bind classes in the correct order calculating some inheritance state
List<XClass> orderedClasses = orderAndFillHierarchy( annotatedClasses );
@@ -633,13 +638,10 @@
annotatedClasses.clear();
annotatedClassEntities.clear();
}
- else {
- log.warn( "Unknown artifact: {}", artifact );
- }
}
- private void removeConflictedArtifact(String artifact) {
- if ( "hbm".equalsIgnoreCase( artifact ) ) {
+ private void removeConflictedArtifact(ConfigurationArtefactType p) {
+ if ( ConfigurationArtefactType.HBM.equals( p ) ) {
for ( String entity : hbmEntities.keySet() ) {
if ( annotatedClassEntities.containsKey( entity ) ) {
annotatedClasses.remove( annotatedClassEntities.get( entity ) );
@@ -647,7 +649,7 @@
}
}
}
- else if ( "class".equalsIgnoreCase( artifact ) ) {
+ else if ( ConfigurationArtefactType.CLASS.equals( p ) ) {
for ( String entity : annotatedClassEntities.keySet() ) {
if ( hbmEntities.containsKey( entity ) ) {
hbmDocuments.remove( hbmEntities.get( entity ) );
@@ -832,23 +834,19 @@
}
public void setPrecedence(String precedence) {
- this.precedence = precedence;
+ this.configurationArtefactPrecedence = parsePrecedence( precedence );
}
- private static class CacheHolder {
- public CacheHolder(String role, String usage, String region, boolean isClass, boolean cacheLazy) {
- this.role = role;
- this.usage = usage;
- this.region = region;
- this.isClass = isClass;
- this.cacheLazy = cacheLazy;
+ private List<ConfigurationArtefactType> parsePrecedence(String s) {
+ if ( StringHelper.isEmpty( s ) ) {
+ return Collections.emptyList();
}
-
- public String role;
- public String usage;
- public String region;
- public boolean isClass;
- public boolean cacheLazy;
+ StringTokenizer precedences = new StringTokenizer( s, ",; ", false );
+ List<ConfigurationArtefactType> tmpPrecedences = new ArrayList<ConfigurationArtefactType>();
+ while ( precedences.hasMoreElements() ) {
+ tmpPrecedences.add( ConfigurationArtefactType.parsePrecedence( ( String ) precedences.nextElement() ) );
+ }
+ return tmpPrecedences;
}
@Override
@@ -860,11 +858,11 @@
* - if it fails because of the version attribute mismatch, try and validate the document with orm_1_0.xsd
*/
List<SAXParseException> errors = new ArrayList<SAXParseException>();
- SAXReader saxReader = new SAXReader( );
+ SAXReader saxReader = new SAXReader();
saxReader.setEntityResolver( getEntityResolver() );
- saxReader.setErrorHandler( new ErrorLogger(errors) );
- saxReader.setMergeAdjacentText(true);
- saxReader.setValidation(true);
+ saxReader.setErrorHandler( new ErrorLogger( errors ) );
+ saxReader.setMergeAdjacentText( true );
+ saxReader.setValidation( true );
setValidationFor( saxReader, "orm_2_0.xsd" );
@@ -880,7 +878,7 @@
if ( e.getCause() == null || !( throwable instanceof SAXParseException ) ) {
throw new MappingException( "Could not parse JPA mapping document", e );
}
- errors.add( (SAXParseException) throwable );
+ errors.add( ( SAXParseException ) throwable );
}
boolean isV1Schema = false;
@@ -889,11 +887,11 @@
final String errorMessage = exception.getMessage();
//does the error look like a schema mismatch?
isV1Schema = doc != null
- && errorMessage.contains("1.0")
- && errorMessage.contains("2.0")
- && errorMessage.contains("version");
+ && errorMessage.contains( "1.0" )
+ && errorMessage.contains( "2.0" )
+ && errorMessage.contains( "version" );
}
- if (isV1Schema) {
+ if ( isV1Schema ) {
//reparse with v1
errors.clear();
setValidationFor( saxReader, "orm_1_0.xsd" );
@@ -903,21 +901,21 @@
}
catch ( DocumentException e ) {
//oops asXML fails even if the core doc parses initially
- throw new AssertionFailure("Error in DOM4J leads to a bug in Hibernate", e);
+ throw new AssertionFailure( "Error in DOM4J leads to a bug in Hibernate", e );
}
}
if ( errors.size() != 0 ) {
//report errors in exception
- StringBuilder errorMessage = new StringBuilder( );
- for (SAXParseException error : errors) {
- errorMessage.append("Error parsing XML (line")
- .append(error.getLineNumber())
- .append(" : column ")
- .append(error.getColumnNumber())
- .append("): ")
- .append(error.getMessage())
- .append("\n");
+ StringBuilder errorMessage = new StringBuilder();
+ for ( SAXParseException error : errors ) {
+ errorMessage.append( "Error parsing XML (line" )
+ .append( error.getLineNumber() )
+ .append( " : column " )
+ .append( error.getColumnNumber() )
+ .append( "): " )
+ .append( error.getMessage() )
+ .append( "\n" );
}
throw new MappingException( "Invalid ORM mapping file.\n" + errorMessage.toString() );
}
@@ -934,25 +932,6 @@
}
}
- private static class ErrorLogger implements ErrorHandler {
- private List<SAXParseException> errors;
-
- public ErrorLogger(List<SAXParseException> errors) {
- this.errors = errors;
- }
-
- public void warning(SAXParseException exception) throws SAXException {
- errors.add( exception );
- }
-
- public void error(SAXParseException exception) throws SAXException {
- errors.add( exception );
- }
-
- public void fatalError(SAXParseException exception) throws SAXException {
- }
- }
-
private void setValidationFor(SAXReader saxReader, String xsd) {
try {
saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
@@ -1267,11 +1246,19 @@
}
//not a public API
+
public ReflectionManager getReflectionManager() {
return reflectionManager;
}
protected class ExtendedMappingsImpl extends MappingsImpl implements ExtendedMappings {
+ private Boolean useNewGeneratorMappings;
+ private Collection<FetchProfile> annotationConfiguredProfile;
+
+ public ExtendedMappingsImpl() {
+ annotationConfiguredProfile = new ArrayList<FetchProfile>();
+ }
+
public void addDefaultGenerator(IdGenerator generator) {
this.addGenerator( generator );
defaultNamedGenerators.add( generator.getName() );
@@ -1288,7 +1275,7 @@
public void addPropertyAnnotatedWithMapsId(XClass entityType, PropertyData property) {
Map<String, PropertyData> map = propertiesAnnotatedWithMapsId.get( entityType );
- if (map == null) {
+ if ( map == null ) {
map = new HashMap<String, PropertyData>();
propertiesAnnotatedWithMapsId.put( entityType, map );
}
@@ -1302,15 +1289,13 @@
public void addToOneAndIdProperty(XClass entityType, PropertyData property) {
Map<String, PropertyData> map = propertiesAnnotatedWithIdAndToOne.get( entityType );
- if (map == null) {
+ if ( map == null ) {
map = new HashMap<String, PropertyData>();
propertiesAnnotatedWithIdAndToOne.put( entityType, map );
}
map.put( property.getPropertyName(), property );
}
- private Boolean useNewGeneratorMappings;
-
@SuppressWarnings({ "UnnecessaryUnboxing" })
public boolean useNewGeneratorMappings() {
if ( useNewGeneratorMappings == null ) {
@@ -1382,6 +1367,7 @@
}
//FIXME should be private but is part of the ExtendedMapping contract
+
public AnnotatedClassType addClassType(XClass clazz) {
AnnotatedClassType type;
if ( clazz.isAnnotationPresent( Entity.class ) ) {
@@ -1420,16 +1406,10 @@
return deprecatedStructure;
}
- /**
- * {@inheritDoc}
- */
public Map<Table, List<UniqueConstraintHolder>> getUniqueConstraintHoldersByTable() {
return uniqueConstraintHoldersByTable;
}
- /**
- * {@inheritDoc}
- */
@SuppressWarnings({ "unchecked" })
public void addUniqueConstraints(Table table, List uniqueConstraints) {
List<UniqueConstraintHolder> constraintHolders = new ArrayList<UniqueConstraintHolder>(
@@ -1437,7 +1417,7 @@
);
int keyNameBase = determineCurrentNumberOfUniqueConstraintHolders( table );
- for ( String[] columns : (List<String[]>)uniqueConstraints ) {
+ for ( String[] columns : ( List<String[]> ) uniqueConstraints ) {
final String keyName = "key" + keyNameBase++;
constraintHolders.add(
new UniqueConstraintHolder().setName( keyName ).setColumns( columns )
@@ -1453,9 +1433,6 @@
: currentHolders.size();
}
- /**
- * {@inheritDoc}
- */
public void addUniqueConstraintHolders(Table table, List<UniqueConstraintHolder> uniqueConstraintHolders) {
List<UniqueConstraintHolder> holderList = getUniqueConstraintHoldersByTable().get( table );
if ( holderList == null ) {
@@ -1550,5 +1527,54 @@
public AnyMetaDef getAnyMetaDef(String name) {
return anyMetaDefs.get( name );
}
+
+ public void addAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
+ annotationConfiguredProfile.add( fetchProfile );
+ }
+
+ public boolean containsAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
+ for ( FetchProfile profile : annotationConfiguredProfile ) {
+ // we need reference equality there!!
+ if ( profile == fetchProfile ) {
+ return true;
+ }
+ }
+ return false;
+ }
}
+
+ private static class CacheHolder {
+ public CacheHolder(String role, String usage, String region, boolean isClass, boolean cacheLazy) {
+ this.role = role;
+ this.usage = usage;
+ this.region = region;
+ this.isClass = isClass;
+ this.cacheLazy = cacheLazy;
+ }
+
+ public String role;
+ public String usage;
+ public String region;
+ public boolean isClass;
+ public boolean cacheLazy;
+ }
+
+ private static class ErrorLogger implements ErrorHandler {
+ private List<SAXParseException> errors;
+
+ public ErrorLogger(List<SAXParseException> errors) {
+ this.errors = errors;
+ }
+
+ public void warning(SAXParseException exception) throws SAXException {
+ errors.add( exception );
+ }
+
+ public void error(SAXParseException exception) throws SAXException {
+ errors.add( exception );
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException {
+ }
+ }
}
Added: core/trunk/annotations/src/main/java/org/hibernate/cfg/ConfigurationArtefactType.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/ConfigurationArtefactType.java (rev 0)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/ConfigurationArtefactType.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,49 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.cfg;
+
+import org.hibernate.HibernateException;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public enum ConfigurationArtefactType {
+ HBM,
+ CLASS;
+
+ static ConfigurationArtefactType parsePrecedence(String s) {
+ if ( s.equalsIgnoreCase( "hbm" ) ) {
+ return HBM;
+ }
+ else if ( s.equalsIgnoreCase( "class" ) ) {
+ return CLASS;
+ }
+ else {
+ throw new HibernateException( "'" + s + "' - invalid value for precedence configuration." );
+ }
+ }
+}
+
+
Property changes on: core/trunk/annotations/src/main/java/org/hibernate/cfg/ConfigurationArtefactType.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2010-03-04 18:15:19 UTC (rev 18923)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -1,3 +1,4 @@
+// $Id:$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -30,12 +31,12 @@
import org.hibernate.AnnotationException;
import org.hibernate.MappingException;
import org.hibernate.annotations.AnyMetaDef;
-import org.hibernate.annotations.Cache;
import org.hibernate.annotations.common.reflection.ReflectionManager;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.engine.NamedQueryDefinition;
import org.hibernate.engine.NamedSQLQueryDefinition;
import org.hibernate.engine.ResultSetMappingDefinition;
+import org.hibernate.mapping.FetchProfile;
import org.hibernate.mapping.IdGenerator;
import org.hibernate.mapping.Join;
import org.hibernate.mapping.PersistentClass;
@@ -47,6 +48,7 @@
* at least for named generators
*
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public interface ExtendedMappings extends Mappings {
@@ -61,6 +63,7 @@
* Retrieve the id-generator by name.
*
* @param name The generator name.
+ *
* @return The generator, or null.
*/
public IdGenerator getGenerator(String name);
@@ -71,6 +74,7 @@
*
* @param name generator name
* @param localGenerators local generators
+ *
* @return the appropriate idgenerator or null if not found
*/
public IdGenerator getGenerator(String name, Map<String, IdGenerator> localGenerators);
@@ -95,6 +99,7 @@
*
* @param name generator name
* @param localGeneratorTables local generator tables
+ *
* @return The properties, or null.
*/
public Properties getGeneratorTableProperties(String name, Map<String, Properties> localGeneratorTables);
@@ -103,6 +108,7 @@
* Retrieve join metadata for a particular persistent entity.
*
* @param entityName The entity name
+ *
* @return The join metadata
*/
public Map<String, Join> getJoins(String entityName);
@@ -112,6 +118,7 @@
*
* @param persistentClass The persistent entity metadata.
* @param joins The join metadata to add.
+ *
* @throws MappingException
*/
public void addJoins(PersistentClass persistentClass, Map<String, Join> joins);
@@ -120,6 +127,7 @@
* Get and maintain a cache of class type.
*
* @param clazz The XClass mapping
+ *
* @return The class type.
*/
public AnnotatedClassType getClassType(XClass clazz);
@@ -129,6 +137,7 @@
* Add a class type.
*
* @param clazz The XClass mapping.
+ *
* @return The class type.
*/
public AnnotatedClassType addClassType(XClass clazz);
@@ -170,7 +179,7 @@
public void addAnyMetaDef(AnyMetaDef defAnn) throws AnnotationException;
public AnyMetaDef getAnyMetaDef(String name);
-
+
public boolean isInSecondPass();
/**
@@ -196,4 +205,16 @@
public PropertyData getPropertyAnnotatedWithIdAndToOne(XClass entityType, String propertyName);
void addToOneAndIdProperty(XClass entity, PropertyData property);
+
+ /**
+ * Add the specified profile to the list of fetch profiles configured via annotations.
+ *
+ * @param fetchProfile the fetch profile
+ */
+ void addAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
+
+ /**
+ * @return {@true} if the provided fetch profile has been configured via xml, {@false otherwise}.
+ */
+ boolean containsAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
}
\ No newline at end of file
Property changes on: core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
___________________________________________________________________
Name: svn:keywords
- Date Revision Author Id
+ Id
Added: core/trunk/annotations/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java (rev 0)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,73 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.cfg;
+
+import java.util.Map;
+
+import org.hibernate.MappingException;
+import org.hibernate.annotations.FetchProfile;
+import org.hibernate.mapping.PersistentClass;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class VerifyFetchProfileReferenceSecondPass implements SecondPass {
+
+ private String fetchProfileName;
+ private FetchProfile.FetchOverride fetch;
+ private ExtendedMappings mappings;
+
+ public VerifyFetchProfileReferenceSecondPass(String fetchProfileName, FetchProfile.FetchOverride fetch, ExtendedMappings mappings) {
+ this.fetchProfileName = fetchProfileName;
+ this.fetch = fetch;
+ this.mappings = mappings;
+ }
+
+ public void doSecondPass(Map persistentClasses) throws MappingException {
+ org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile( fetchProfileName );
+ if ( skipProfile( profile ) ) {
+ return;
+ }
+
+ PersistentClass clazz = mappings.getClass( fetch.entity().getName() );
+ // throws MappingException in case the property does not exist
+ clazz.getProperty( fetch.association() );
+
+ profile.addFetch(
+ fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase()
+ );
+ }
+
+ private boolean skipProfile(org.hibernate.mapping.FetchProfile profile) {
+ if ( mappings.containsAnnotationConfiguredFetchProfile( profile ) ) {
+ return false;
+ }
+
+ // if there are fetches they must come from xml. If there are xml profiles the annotations get ignored
+ return !profile.getFetches().isEmpty();
+ }
+}
+
+
Property changes on: core/trunk/annotations/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/ConfigurationTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/ConfigurationTest.java 2010-03-04 18:15:19 UTC (rev 18923)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/ConfigurationTest.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -36,7 +36,7 @@
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
- cfg.setProperty( AnnotationConfiguration.ARTEFACT, "class, whatever" );
+ cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class" );
SessionFactory sf = cfg.buildSessionFactory();
assertNotNull( sf );
Session s = sf.openSession();
@@ -85,7 +85,7 @@
AnnotationConfiguration cfg = new AnnotationConfiguration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
- cfg.setProperty( AnnotationConfiguration.ARTEFACT, "class, hbm" );
+ cfg.setProperty( AnnotationConfiguration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
cfg.addAnnotatedClass( Boat.class );
SessionFactory sf = cfg.buildSessionFactory();
assertNotNull( sf );
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/ConfigurationTest.java
___________________________________________________________________
Name: svn:keywords
- Date Revision Author Id
+ Id
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/any/package-info.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/any/package-info.java 2010-03-04 18:15:19 UTC (rev 18923)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/any/package-info.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -1,4 +1,4 @@
-//$Id:
+// $Id:$
@AnyMetaDefs(
@AnyMetaDef( name= "Property", metaType = "string", idType = "integer",
metaValues = {
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,92 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.test.annotations.fetchprofile;
+
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.FetchMode;
+import org.hibernate.annotations.FetchProfile;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@FetchProfile(name = "customer-with-orders", fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN)
+})
+public class Customer {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ private String name;
+
+ private long customerNumber;
+
+ @OneToMany
+ private Set<Order> orders;
+
+ @OneToMany
+ private Set<SupportTickets> tickets;
+
+ public long getCustomerNumber() {
+ return customerNumber;
+ }
+
+ public void setCustomerNumber(long customerNumber) {
+ this.customerNumber = customerNumber;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set<Order> getOrders() {
+ return orders;
+ }
+
+ public void setOrders(Set<Order> orders) {
+ this.orders = orders;
+ }
+}
+
+
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer2.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer2.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer2.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,88 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.test.annotations.fetchprofile;
+
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.FetchMode;
+import org.hibernate.annotations.FetchProfile;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@FetchProfile(name = "customer-with-orders", fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Customer2.class, association = "foo", mode = FetchMode.JOIN)
+})
+public class Customer2 {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ private String name;
+
+ private long customerNumber;
+
+ @OneToMany
+ private Set<Order> orders;
+
+ public long getCustomerNumber() {
+ return customerNumber;
+ }
+
+ public void setCustomerNumber(long customerNumber) {
+ this.customerNumber = customerNumber;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set<Order> getOrders() {
+ return orders;
+ }
+
+ public void setOrders(Set<Order> orders) {
+ this.orders = orders;
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer2.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer3.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer3.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer3.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,88 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.test.annotations.fetchprofile;
+
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.FetchMode;
+import org.hibernate.annotations.FetchProfile;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@FetchProfile(name = "wrong-class-name", fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Order.class, association = "orders", mode = FetchMode.JOIN)
+})
+public class Customer3 {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ private String name;
+
+ private long customerNumber;
+
+ @OneToMany
+ private Set<Order> orders;
+
+ public long getCustomerNumber() {
+ return customerNumber;
+ }
+
+ public void setCustomerNumber(long customerNumber) {
+ this.customerNumber = customerNumber;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set<Order> getOrders() {
+ return orders;
+ }
+
+ public void setOrders(Set<Order> orders) {
+ this.orders = orders;
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer3.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer4.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer4.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer4.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,88 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.test.annotations.fetchprofile;
+
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.FetchMode;
+import org.hibernate.annotations.FetchProfile;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@FetchProfile(name = "unsupported-fetch-mode", fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Customer4.class, association = "orders", mode = FetchMode.SELECT)
+})
+public class Customer4 {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ private String name;
+
+ private long customerNumber;
+
+ @OneToMany
+ private Set<Order> orders;
+
+ public long getCustomerNumber() {
+ return customerNumber;
+ }
+
+ public void setCustomerNumber(long customerNumber) {
+ this.customerNumber = customerNumber;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set<Order> getOrders() {
+ return orders;
+ }
+
+ public void setOrders(Set<Order> orders) {
+ this.orders = orders;
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer4.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer5.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer5.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer5.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,88 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.test.annotations.fetchprofile;
+
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.FetchMode;
+import org.hibernate.annotations.FetchProfile;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@FetchProfile(name = "orders-profile", fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Customer5.class, association = "foo", mode = FetchMode.JOIN)
+})
+public class Customer5 {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ private String name;
+
+ private long customerNumber;
+
+ @OneToMany
+ private Set<Order> orders;
+
+ public long getCustomerNumber() {
+ return customerNumber;
+ }
+
+ public void setCustomerNumber(long customerNumber) {
+ this.customerNumber = customerNumber;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set<Order> getOrders() {
+ return orders;
+ }
+
+ public void setOrders(Set<Order> orders) {
+ this.orders = orders;
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Customer5.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java (from rev 18918, core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fkcircularity/FkCircularityTest.java)
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/FetchProfileTest.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,151 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.test.annotations.fetchprofile;
+
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.hibernate.MappingException;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.engine.SessionFactoryImplementor;
+
+/**
+ * Test case for HHH-4812
+ *
+ * @author Hardy Ferentschik
+ */
+public class FetchProfileTest extends TestCase {
+
+ private Logger log = LoggerFactory.getLogger( FetchProfileTest.class );
+
+ public void testFetchProfileConfigured() {
+ AnnotationConfiguration config = new AnnotationConfiguration();
+ config.addAnnotatedClass( Customer.class );
+ config.addAnnotatedClass( Order.class );
+ config.addAnnotatedClass( SupportTickets.class );
+ SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory();
+
+ assertTrue(
+ "fetch profile not parsed properly",
+ sessionImpl.containsFetchProfileDefinition( "customer-with-orders" )
+ );
+ assertFalse(
+ "package info should not be parsed",
+ sessionImpl.containsFetchProfileDefinition( "package-profile-1" )
+ );
+ }
+
+ public void testWrongAssociationName() {
+ AnnotationConfiguration config = new AnnotationConfiguration();
+ config.addAnnotatedClass( Customer2.class );
+ config.addAnnotatedClass( Order.class );
+
+ try {
+ config.buildSessionFactory();
+ fail();
+ }
+ catch ( MappingException e ) {
+ log.trace( "success" );
+ }
+ }
+
+ public void testWrongClass() {
+ AnnotationConfiguration config = new AnnotationConfiguration();
+ config.addAnnotatedClass( Customer3.class );
+ config.addAnnotatedClass( Order.class );
+
+ try {
+ config.buildSessionFactory();
+ fail();
+ }
+ catch ( MappingException e ) {
+ log.trace( "success" );
+ }
+ }
+
+ public void testUnsupportedFetchMode() {
+ AnnotationConfiguration config = new AnnotationConfiguration();
+ config.addAnnotatedClass( Customer4.class );
+ config.addAnnotatedClass( Order.class );
+
+ try {
+ config.buildSessionFactory();
+ fail();
+ }
+ catch ( MappingException e ) {
+ log.trace( "success" );
+ }
+ }
+
+ public void testXmlOverride() {
+ AnnotationConfiguration config = new AnnotationConfiguration();
+ config.addAnnotatedClass( Customer5.class );
+ config.addAnnotatedClass( Order.class );
+ InputStream is = Thread.currentThread()
+ .getContextClassLoader()
+ .getResourceAsStream( "org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml" );
+ config.addInputStream( is );
+ SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory();
+
+ assertTrue(
+ "fetch profile not parsed properly",
+ sessionImpl.containsFetchProfileDefinition( "orders-profile" )
+ );
+
+ // now the same with no xml
+ config = new AnnotationConfiguration();
+ config.addAnnotatedClass( Customer5.class );
+ config.addAnnotatedClass( Order.class );
+ try {
+ config.buildSessionFactory();
+ fail();
+ }
+ catch ( MappingException e ) {
+ log.trace( "success" );
+ }
+ }
+
+ public void testPackageConfiguredFetchProfile() {
+ AnnotationConfiguration config = new AnnotationConfiguration();
+ config.addAnnotatedClass( Customer.class );
+ config.addAnnotatedClass( Order.class );
+ config.addAnnotatedClass( SupportTickets.class );
+ config.addPackage( Customer.class.getPackage().getName() );
+ SessionFactoryImplementor sessionImpl = ( SessionFactoryImplementor ) config.buildSessionFactory();
+
+ assertTrue(
+ "fetch profile not parsed properly",
+ sessionImpl.containsFetchProfileDefinition( "package-profile-1" )
+ );
+ assertTrue(
+ "fetch profile not parsed properly",
+ sessionImpl.containsFetchProfileDefinition( "package-profile-2" )
+ );
+ }
+}
\ No newline at end of file
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Order.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Order.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Order.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,71 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.test.annotations.fetchprofile;
+
+import java.util.Date;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class Order {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ private long orderNumber;
+
+ private Date deliveryDate;
+
+ public Date getDeliveryDate() {
+ return deliveryDate;
+ }
+
+ public void setDeliveryDate(Date deliveryDate) {
+ this.deliveryDate = deliveryDate;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public long getOrderNumber() {
+ return orderNumber;
+ }
+
+ public void setOrderNumber(long orderNumber) {
+ this.orderNumber = orderNumber;
+ }
+}
+
+
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/Order.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/SupportTickets.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/SupportTickets.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/SupportTickets.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,70 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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.test.annotations.fetchprofile;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class SupportTickets {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ private String description;
+
+ private String resolution;
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getResolution() {
+ return resolution;
+ }
+
+ public void setResolution(String resolution) {
+ this.resolution = resolution;
+ }
+}
+
+
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/SupportTickets.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/package-info.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/package-info.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/package-info.java 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,41 @@
+// $Id:$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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.
+ *
+ * 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
+ *
+ */
+@FetchProfiles({
+ @FetchProfile(name = "package-profile-1", fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Customer.class, association = "orders", mode = FetchMode.JOIN)
+ }),
+ @FetchProfile(name = "package-profile-2", fetchOverrides = {
+ @FetchProfile.FetchOverride(entity = Customer.class, association = "tickets", mode = FetchMode.JOIN)
+ })
+})
+package org.hibernate.test.annotations.fetchprofile;
+
+import org.hibernate.annotations.FetchMode;
+import org.hibernate.annotations.FetchProfile;
+import org.hibernate.annotations.FetchProfiles;
+
+
+
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/package-info.java
___________________________________________________________________
Name: svn:keywords
+ Id
Copied: core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml (from rev 18922, core/trunk/testsuite/src/test/java/org/hibernate/test/fetchprofiles/join/Mappings.hbm.xml)
===================================================================
--- core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml (rev 0)
+++ core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml 2010-03-04 21:55:10 UTC (rev 18924)
@@ -0,0 +1,35 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping
+ SYSTEM
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
+
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2008, Red Hat Middleware LLC 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.
+ ~
+ ~ 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
+ ~
+ -->
+
+<hibernate-mapping package="org.hibernate.test.annotations.fetchprofile">
+ <fetch-profile name="orders-profile">
+ <fetch entity="Customer5" association="orders" style="join"/>
+ </fetch-profile>
+</hibernate-mapping>
Property changes on: core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/entitymanager/pom.xml
===================================================================
--- core/trunk/entitymanager/pom.xml 2010-03-04 18:15:19 UTC (rev 18923)
+++ core/trunk/entitymanager/pom.xml 2010-03-04 21:55:10 UTC (rev 18924)
@@ -65,7 +65,7 @@
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-impl-base</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.0.0-alpha-6</version>
<scope>test</scope>
</dependency>
<dependency>
Property changes on: core/trunk/entitymanager/pom.xml
___________________________________________________________________
Name: svn:keywords
+ Id
14 years, 10 months
Hibernate SVN: r18923 - in core/trunk: entitymanager/src/main/docbook/en and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-03-04 13:15:19 -0500 (Thu, 04 Mar 2010)
New Revision: 18923
Modified:
core/trunk/annotations/src/main/docbook/en/modules/setup.xml
core/trunk/entitymanager/src/main/docbook/en/master.xml
core/trunk/entitymanager/src/main/docbook/en/modules/architecture.xml
core/trunk/entitymanager/src/main/docbook/en/modules/batch.xml
core/trunk/entitymanager/src/main/docbook/en/modules/configuration.xml
core/trunk/entitymanager/src/main/docbook/en/modules/entitymanagerapi.xml
core/trunk/entitymanager/src/main/docbook/en/modules/listeners.xml
core/trunk/entitymanager/src/main/docbook/en/modules/query_ejbql.xml
core/trunk/entitymanager/src/main/docbook/en/modules/query_native.xml
core/trunk/entitymanager/src/main/docbook/en/modules/transactions.xml
Log:
HHH-4933 Work on HEM doc, refreshing it for JPA 2. architecture and configuration refreshed
Modified: core/trunk/annotations/src/main/docbook/en/modules/setup.xml
===================================================================
--- core/trunk/annotations/src/main/docbook/en/modules/setup.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/annotations/src/main/docbook/en/modules/setup.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -51,7 +51,7 @@
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
+ <artifactId>hibernate-annotations</artifactId>
<version>${hibernate-core-version}</version>
</dependency>
</dependencies>
@@ -66,8 +66,8 @@
<para>First, set up your classpath (after you have created a new project
in your favorite IDE): <itemizedlist>
<listitem>
- <para>Copy all Hibernate3 core and required 3rd party library
- files.</para>
+ <para>Copy <filename>hibernate-core.jar</filename> and required 3rd
+ party library files.</para>
</listitem>
<listitem>
Modified: core/trunk/entitymanager/src/main/docbook/en/master.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/master.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/entitymanager/src/main/docbook/en/master.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -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,80 +22,129 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY version "WORKING">
<!ENTITY today "TODAY">
]>
-
<book>
-
<bookinfo>
<title>Hibernate EntityManager</title>
+
<subtitle>User guide</subtitle>
- <releaseinfo>&version;</releaseinfo>
- <edition>1.0</edition>
- <pubsnumber>1</pubsnumber>
- <pubdate>&today;</pubdate>
- <productnumber>&version;</productnumber>
- <issuenum>1</issuenum>
- <mediaobject>
- <imageobject>
- <imagedata fileref="images/hibernate_logo_a.png" format="PNG"/>
- </imageobject>
- </mediaobject>
- <copyright>
- <year>2005</year>
- <holder>Red Hat Inc.</holder>
- </copyright>
+
+ <releaseinfo>&version;</releaseinfo>
+
+ <edition>1.0</edition>
+
+ <pubsnumber>1</pubsnumber>
+
+ <pubdate>&today;</pubdate>
+
+ <productnumber>&version;</productnumber>
+
+ <issuenum>1</issuenum>
+
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="images/hibernate_logo_a.png" format="PNG" />
+ </imageobject>
+ </mediaobject>
+
+ <copyright>
+ <year>2005</year>
+
+ <holder>Red Hat Inc. and the various authors</holder>
+ </copyright>
+
+ <authorgroup>
+ <author>
+ <firstname>Emmanuel</firstname>
+
+ <surname>Bernard</surname>
+ </author>
+
+ <author>
+ <firstname>Steve</firstname>
+
+ <surname>Ebersole</surname>
+ </author>
+
+ <!--TODO add translators like core did -->
+ </authorgroup>
</bookinfo>
- <toc/>
+ <toc></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>
+ <title>Introducing JPA Persistence</title>
+
+ <para>The JPA specification recognizes the interest and the success of the
+ transparent object/relational mapping paradigm. It 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 JPA 2.0
+ specification. Together with <emphasis>Hibernate Annotations</emphasis>,
+ this wrapper implements a complete (and standalone) JPA persistence
+ solution on top of the mature Hibernate Core. You may use a combination of
+ all three together, annotations without JPA programming interfaces and
+ lifecycle, or even pure native Hibernate Core, 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 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/metamodel.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"/>
+ <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/metamodel.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>
+
+ <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>
+
+ <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>
-
</book>
Modified: core/trunk/entitymanager/src/main/docbook/en/modules/architecture.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/architecture.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/architecture.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -1,11 +1,11 @@
-<?xml version='1.0' encoding="UTF-8"?>
+<?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) 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
@@ -22,24 +22,23 @@
~ 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="architecture">
<title>Architecture</title>
<section>
<title>Definitions</title>
- <para>EJB3 is part of the Java EE 5.0 platform. Persistence in EJB3 is
- available in EJB3 containers, as well as for standalone J2SE applications
+ <para>JPA 2 is part of the Java EE 6.0 platform. Persistence in JPA is
+ available in containers like EJB 3 or the more modern CDI (Java Context
+ and Dependency Injection), as well as in standalone Java SE applications
that execute outside of a particular container. The following programming
interfaces and artifacts are available in both environments.</para>
<variablelist spacing="compact">
<varlistentry>
- <term>
- <literal>EntityManagerFactory</literal>
- </term>
+ <term><literal>EntityManagerFactory</literal></term>
<listitem>
<para>An entity manager factory provides entity manager instances,
@@ -52,9 +51,7 @@
</varlistentry>
<varlistentry>
- <term>
- <literal>EntityManager</literal>
- </term>
+ <term><literal>EntityManager</literal></term>
<listitem>
<para>The <literal>EntityManager</literal> API is used to access a
@@ -128,7 +125,7 @@
</section>
<section>
- <title>EJB container environment</title>
+ <title>In container environment (eg. EJB 3)</title>
<section>
<title>Container-managed entity manager</title>
@@ -170,16 +167,16 @@
<para>The most common case is to bind the persistence context scope to
the current transaction scope. This is only doable when JTA transactions
are used: the persistence context is associated with the JTA transaction
- life cycle. When a entity manager is invoked, the persistence context is
- also opened, if there is no persistence context associated with the
+ life cycle. When an entity manager is invoked, the persistence context
+ is also opened, if there is no persistence context associated with the
current JTA transaction. Otherwise, the associated persistence context
is used. The persistence context ends when the JTA transaction
completes. This means that during the JTA transaction, an application
will be able to work on managed entities of the same persistence
context. In other words, you don't have to pass the entity manager's
- persistence context across your EJB method calls, but simply use
- dependency injection or lookup whenever you need an entity
- manager.</para>
+ persistence context across your managed beans (CDI) or EJBs method
+ calls, but simply use dependency injection or lookup whenever you need
+ an entity manager.</para>
<para>You can also use an extended persistence context. This can be
combined with stateful session beans, if you use a container-managed
@@ -194,16 +191,18 @@
view of the application user, and implement it using an extended
persistence context. Please refer to the Hibernate reference manual or
the book Hibernate In Action for more information about this pattern.
- JBoss Seam is a framework that link together JSF and EJB3 around the
- notion of conversation and unit of work. For an application-managed
+ </para>
+
+ <para>JBoss Seam 3 is built on top of CDI and has at it's core concept
+ the notion of conversation and unit of work. For an application-managed
entity manager the persistence context is created when the entity
manager is created and kept until the entity manager is closed. In an
extended persistence context, all modification operations (persist,
merge, remove) executed outside a transaction are queued until the
persistence context is attached to a transaction. The transaction
typically occurs at the user process end, allowing the whole process to
- be commited or rollbacked. For application-managed entity manager only
- support the exctended persistence context.</para>
+ be committed or rollbacked. For application-managed entity manager only
+ support the extended persistence context.</para>
<para>A resource-local entity manager or an entity manager created with
<literal>EntityManagerFactory.createEntityManager()</literal>
@@ -235,7 +234,8 @@
<para>If a stateless session bean, message-driven bean, or stateful
session bean with a transaction-scoped persistence context calls a
stateful session bean with an extended persistence context in the
- same JTA transaction, an IllegalStateException is thrown.</para>
+ same JTA transaction, an
+ <classname>IllegalStateException</classname> is thrown.</para>
</listitem>
<listitem>
@@ -265,7 +265,7 @@
<para>If a stateful session bean with an extended persistence
context calls a stateful session bean with a different extended
persistence context in the same transaction, an
- IllegalStateException is thrown.</para>
+ <classname>IllegalStateException</classname> is thrown.</para>
</listitem>
</itemizedlist>
</section>
@@ -274,7 +274,7 @@
<section id="architecture-javase" revision="1">
<title>Java SE environments</title>
- <para>In a Java SE environment only extented context application-managed
+ <para>In a Java SE environment only extended context application-managed
entity managers are available. You can retrieve an entity manger using the
<literal>EntityManagerFactory</literal> API. Only resource-local entity
managers are available. In other words, JTA transactions and persistence
@@ -288,4 +288,4 @@
closed when the entity manager is closed. Many resource-local transaction
share the same persistence context, in this case.</para>
</section>
-</chapter>
\ No newline at end of file
+</chapter>
Modified: core/trunk/entitymanager/src/main/docbook/en/modules/batch.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/batch.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/batch.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -2,10 +2,10 @@
<!--
~ 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.
+ ~ 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
Modified: core/trunk/entitymanager/src/main/docbook/en/modules/configuration.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/configuration.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/configuration.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -1,11 +1,11 @@
-<?xml version='1.0' encoding="UTF-8"?>
+<?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.
+ ~ 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
@@ -22,22 +22,64 @@
~ 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="configuration">
<title id="setup">Setup and configuration</title>
<section>
<title>Setup</title>
- <para>The EJB 3.0 / JPA compatible Hibernate EntityManager is built on top
- of Hibernate core and Hibernate Annotations. You have to use compatible
- versions of each module. Please consult the compatibility matrix in the
- hibernate.org download section. The following libraries have to be in your
- classpath: hibernate3.jar, hibernate-annotations.jar,
+ <para>The JPA 2.0 compatible Hibernate EntityManager is built on top of
+ the core of Hibernate and Hibernate Annotations. Starting from version
+ 3.5, we have bundled in a single Hibernate distribution all the necessary
+ modules:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>Hibernate Core: the native Hibernate APIs and core engine</para>
+ </listitem>
+
+ <listitem>
+ <para>Hibernate Annotations: the annotation-based mapping</para>
+ </listitem>
+
+ <listitem>
+ <para>Hibernate EntityManager: the JPA 2.0 APIs and livecycle semantic
+ implementation</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>The following libraries have to be in your classpath:
+ hibernate-core.jar, hibernate-annotations.jar,
hibernate-commons-annotations.jar, hibernate-entitymanager.jar and all
needed third party libraries for each package (incl.
- ejb-persistence.jar).</para>
+ hibernate-jpa-2.0-api.jar).</para>
+
+ <note>
+ <title>What is hibernate-jpa-2.0-api-x.y.z.jar</title>
+
+ <para>This is the JAR containing the JPA 2.0 API, it is fully compliant
+ with the spec and passed the TCK signature test. You typically don't
+ need it when you deploy your application in a Java EE 6 application
+ server (like JBoss AS 6 for example).</para>
+ </note>
+
+ <para>If you use Maven, add the following dependencies</para>
+
+ <programlisting><project ...>
+ ...
+ <dependencies>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>${hibernate-core-version}</version>
+ </dependency>
+ </dependencies>
+</project></programlisting>
+
+ <para>All the required dependencies like hibernate-core and
+ hibernate-annotations will be dragged transitively.</para>
</section>
<section id="setup-configuration"
@@ -52,16 +94,16 @@
A persistence archive is a JAR file which must define a
<literal>persistence.xml</literal> file that resides in the
<filename>META-INF</filename> folder. All properly annotated classes
- included in the archive (ie having an <literal>@Entity</literal>
+ included in the archive (ie. having an <literal>@Entity</literal>
annotation), all annotated packages and all Hibernate hbm.xml files
included in the archive will be added to the persistence unit
configuration, so by default, your persistence.xml will be quite
minimalist:</para>
<programlisting><persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
- version="1.0">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+ version="2.0">
<persistence-unit name="sample">
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
@@ -75,9 +117,9 @@
<filename><literal>persistence.xml</literal></filename> file</para>
<programlisting><persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
- version="1.0">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+ version="2.0">
<persistence-unit name="manager1" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/DefaultDS</jta-data-source>
@@ -86,6 +128,8 @@
<class>org.acme.Employee</class>
<class>org.acme.Person</class>
<class>org.acme.Address</class>
+ <shared-cache-mode>ENABLE_SELECTOVE</shared-cache-mode>
+ <validation-mode>CALLBACK</validation-mode>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
@@ -199,6 +243,100 @@
</varlistentry>
<varlistentry>
+ <term>shared-cache-mode</term>
+
+ <listitem>
+ <para>By default, entities are elected for second-level cache if
+ annotated with <classname>@Cacheable</classname>. You can
+ however:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para><literal>ALL</literal>: force caching for all
+ entities</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>NONE</literal>: disable caching for all
+ entities (useful to take second-level cache out of the
+ equation)</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>ENABLE_SELECTIVE</literal> (default): enable
+ caching when explicitly marked</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>DISABLE_SELECTIVE</literal>: enable caching
+ unless explicitly marked as
+ <classname>@Cacheable(false)</classname> (not
+ recommended)</para>
+ </listitem>
+ </itemizedlist>
+
+ <para> See Hibernate Annotation's documentation for more
+ details.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>validation-mode</term>
+
+ <listitem>
+ <para>By default, Bean Validation (and Hibernate Validator) is
+ activated. When an entity is created, updated (and optionally
+ deleted), it is validated before being sent to the database. The
+ database schema generated by Hibernate also reflects the
+ constraints declared on the entity.</para>
+
+ <para>You can fine-tune that if needed:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para><literal>AUTO</literal>: if Bean Validation is present
+ in the classpath, CALLBACK and DDL are activated.</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>CALLBACK</literal>: entities are validated on
+ creation, update and deletion. If no Bean Validation provider
+ is present, an exception is raised at initialization
+ time.</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>DDL</literal>: (not standard, see below)
+ database schemas are entities are validated on creation,
+ update and deletion. If no Bean Validation provider is
+ present, an exception is raised at initialization time.</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>NONE</literal>: Bean Validation is not used at
+ all</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>Unfortunately, <literal>DDL</literal> is not standard mode
+ (though extremely useful) and you will not be able to put it in
+ <literal><validation-mode></literal>. To use it, add a
+ regular property</para>
+
+ <programlisting><property name="javax.persistence.validation.mode">
+ ddl
+</property></programlisting>
+
+ <para>With this approach, you can mix ddl and callback
+ modes:</para>
+
+ <programlisting><property name="javax.persistence.validation.mode">
+ ddl, callback
+</property></programlisting>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><code>properties</code></term>
<listitem>
@@ -206,63 +344,165 @@
properties. This is where you will define your Hibernate specific
configurations. This is also where you will have to specify JDBC
connection information as well.</para>
+
+ <para>Here is a list of JPA 2 standard properties. Be sure to also
+ Hibernate Core's documentation to see Hibernate specific
+ properties.</para>
+
+ <itemizedlist>
+ <listitem>
+ <para><literal>javax.persistence.lock.timeout</literal>
+ pessimistic lock timeout in milliseconds
+ (<classname>Integer</classname> or
+ <classname>String</classname>), this is a hint used by
+ Hibernate but requires support by your underlying
+ database.</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>javax.persistence.query.timeout</literal> query
+ timeout in milliseconds (<classname>Integer</classname> or
+ <classname>String</classname>), this is a hint used by
+ Hibernate but requires support by your underlying database
+ (TODO is that 100% true or do we use some other
+ tricks).</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>javax.persistence.validation.mode</literal>
+ corresponds to the <literal>validation-mode</literal> element.
+ Use it if you wish to use the non standard
+ <literal>DDL</literal> value.</para>
+ </listitem>
+
+ <listitem>
+ <para>javax.persistence.validation.group.pre-persist defines
+ the group or list of groups to validate before persisting an
+ entity. This is a comma separated fully qualified class name
+ string (eg <code>com.acme.groups.Common</code> or
+ <code>com.acme.groups.Common,
+ javax.validation.groups.Default</code>)</para>
+ </listitem>
+ </itemizedlist>
+
+ <note>
+ <para>To know more about Bean Validation and Hibernate
+ Validator, check out Hibernate Validator's reference
+ documentation as well as Hibernate Annotations's documentation
+ on Bean Validation.</para>
+ </note>
+
+ <para>The following properties can only be used in a SE
+ environment where no datasource/JNDI is available:</para>
+
+ <itemizedlist>
+ <listitem>
+ <para><literal>javax.persistence.jdbc.driver</literal>: the
+ fully qualified class name of the driver class</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>javax.persistence.jdbc.url</literal>: the
+ driver specific URL</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>javax.persistence.jdbc.user</literal> the user
+ name used for the database connection</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>javax.persistence.jdbc.password</literal> the
+ password used for the database connection</para>
+ </listitem>
+ </itemizedlist>
</listitem>
</varlistentry>
</variablelist>
<para>Be sure to define the grammar definition in the
- <literal>persistence</literal> element since the EJB3 specification
- requires the schema validation. If the systemId ends with
- <literal>persistence_1_0.xsd</literal>, Hibernate entityManager will use
- the version embedded in the hibernate-entitymanager.jar. No internet
- access will be processed.</para>
+ <literal>persistence</literal> element since the JPA specification
+ requires schema validation. If the <literal>systemId</literal> ends with
+ <literal>persistence_2_0.xsd</literal>, Hibernate entityManager will use
+ the version embedded in the hibernate-entitymanager.jar. It won't fetch
+ the resource from the internet.</para>
<programlisting><persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
- version="1.0"></programlisting>
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+ version="2.0"></programlisting>
</section>
<section id="setup-configuration-bootstrapping" revision="1">
<title>Bootstrapping</title>
- <para>The EJB3 specification defines a bootstrap procedure to access the
+ <para>The JPA specification defines a bootstrap procedure to access the
<classname>EntityManagerFactory</classname> and the
<classname>EntityManager</classname>. The bootstrap class is
<classname>javax.persistence.Persistence</classname>, e.g.</para>
<programlisting>EntityManagerFactory emf = Persistence.createEntityManagerFactory("manager1");
+
//or
-Map configOverrides = new HashMap();
+
+Map<String, Object> configOverrides = new HashMap<String, Object>();
configOverrides.put("hibernate.hbm2ddl.auto", "create-drop");
EntityManagerFactory programmaticEmf =
Persistence.createEntityManagerFactory("manager1", configOverrides);</programlisting>
<para>The first version is equivalent to the second with an empty map.
The map version is a set of overrides that will take precedence over any
- properties defined in your persistence.xml files. There are a couple of
- EJB3 properties usable in the map:</para>
+ properties defined in your <filename>persistence.xml</filename> files.
+ All the properties defined in <xref
+ linkend="setup-configuration-packaging" /> can be passed to the
+ <methodname>createEntityManagerFactory</methodname> method and there are
+ a few additional ones:</para>
<itemizedlist>
<listitem>
- <para>javax.persistence.provider to define the provider class
- used</para>
+ <para><literal>javax.persistence.provider</literal> to define the
+ provider class used</para>
</listitem>
<listitem>
- <para>javax.persistence.transactionType to define the transaction
- type used (either JTA or RESOURCE_LOCAL)</para>
+ <para><literal>javax.persistence.transactionType</literal> to define
+ the transaction type used (either <literal>JTA</literal> or
+ <literal>RESOURCE_LOCAL</literal>)</para>
</listitem>
<listitem>
- <para>javax.persistence.jtaDataSource to define the JTA datasource
- name in JNDI</para>
+ <para><literal>javax.persistence.jtaDataSource</literal> to define
+ the JTA datasource name in JNDI</para>
</listitem>
<listitem>
- <para>javax.persistence.nonJtaDataSource to define the non JTA
- datasource name in JNDI</para>
+ <para><literal>javax.persistence.nonJtaDataSource</literal> to
+ define the non JTA datasource name in JNDI</para>
</listitem>
+
+ <listitem>
+ <para><literal>javax.persistence.lock.timeout</literal> pessimistic
+ lock timeout in milliseconds (<classname>Integer</classname> or
+ <classname>String</classname>)</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>javax.persistence.query.timeout</literal> query
+ timeout in milliseconds (<classname>Integer</classname> or
+ <classname>String</classname>)</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>javax.persistence.sharedCache.mode</literal>
+ corresponds to the <literal>share-cache-mode</literal> element
+ defined in <xref linkend="setup-configuration-packaging" />.</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>javax.persistence.validation.mode</literal>
+ corresponds to the <literal>validation-mode</literal> element
+ defined in <xref linkend="setup-configuration-packaging" />.</para>
+ </listitem>
</itemizedlist>
<para>When <code>Persistence.createEntityManagerFactory()</code> is
@@ -423,7 +663,7 @@
though.</para>
</note>
- <para>Here is a typical configuration in a J2SE environment</para>
+ <para>Here is a typical configuration in a Java SE environment</para>
<programlisting><persistence>
<persistence-unit name="manager1" transaction-type="RESOURCE_LOCAL">
@@ -431,11 +671,11 @@
<class>org.hibernate.ejb.test.Distributor</class>
<class>org.hibernate.ejb.test.Item</class>
<properties>
- <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
- <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
- <property name="hibernate.connection.username" value="sa"/>
- <property name="hibernate.connection.password" value=""/>
- <property name="hibernate.connection.url" value="jdbc:hsqldb:."/>
+ <property name="<literal>javax.persistence.jdbc.driver</literal>" value="org.hsqldb.jdbcDriver"/>
+ <property name="<literal>javax.persistence.jdbc.user</literal>" value="sa"/>
+ <property name="<literal>javax.persistence.jdbc.password</literal>" value=""/>
+ <property name="<literal>javax.persistence.jdbc.url</literal>" value="jdbc:hsqldb:."/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/
<property name="hibernate.max_fetch_depth" value="3"/>
<!-- cache configuration -->
@@ -603,8 +843,8 @@
</tgroup>
</table>
- <para>Note that the JACC*EventListeners are removed if the security is not
- enabled.</para>
+ <para>Note that the <classname>JACC*EventListeners</classname> are removed
+ if the security is not enabled.</para>
<para>You can configure the event listeners either through the properties
(see <xref linkend="setup-configuration" />) or through the
@@ -636,12 +876,13 @@
manager factory is a wrapper on top of a session factory. Calls to the
entityManagerFactory are thread safe.</para>
- <para>Thanks to the EntityManagerFactory, you can retrieve an extended
- entity manager. The extended entity manager keep the same persistence
- context for the lifetime of the entity manager: in other words, the
- entities are still managed between two transactions (unless you call
- entityManager.clear() in between). You can see an entity manager as a
- small wrapper on top of an Hibernate session.</para>
+ <para>Thanks to the <classname>EntityManagerFactory</classname>, you can
+ retrieve an extended entity manager. The extended entity manager keep the
+ same persistence context for the lifetime of the entity manager: in other
+ words, the entities are still managed between two transactions (unless you
+ call <methodname>entityManager.clear()</methodname> in between). You can
+ see an entity manager as a small wrapper on top of an Hibernate
+ session.</para>
<para>TODO explains emf.createEntityManager(Map)</para>
</section>
@@ -655,4 +896,4 @@
be no performance cost. For more information on Hibernate Validator,
please refer to the Hibernate Annotations reference guide.</para>
</section>
-</chapter>
\ No newline at end of file
+</chapter>
Modified: core/trunk/entitymanager/src/main/docbook/en/modules/entitymanagerapi.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/entitymanagerapi.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/entitymanagerapi.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -2,10 +2,10 @@
<!--
~ 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.
+ ~ 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
Modified: core/trunk/entitymanager/src/main/docbook/en/modules/listeners.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/listeners.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/listeners.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -2,10 +2,10 @@
<!--
~ 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.
+ ~ 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
Modified: core/trunk/entitymanager/src/main/docbook/en/modules/query_ejbql.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/query_ejbql.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/query_ejbql.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -2,10 +2,10 @@
<!--
~ 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.
+ ~ 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
Modified: core/trunk/entitymanager/src/main/docbook/en/modules/query_native.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/query_native.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/query_native.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -2,10 +2,10 @@
<!--
~ 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.
+ ~ 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
Modified: core/trunk/entitymanager/src/main/docbook/en/modules/transactions.xml
===================================================================
--- core/trunk/entitymanager/src/main/docbook/en/modules/transactions.xml 2010-03-03 22:37:31 UTC (rev 18922)
+++ core/trunk/entitymanager/src/main/docbook/en/modules/transactions.xml 2010-03-04 18:15:19 UTC (rev 18923)
@@ -2,10 +2,10 @@
<!--
~ 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.
+ ~ 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
14 years, 10 months
Hibernate SVN: r18922 - annotations/branches/v3_3_1_GA_CP.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-03-03 17:37:31 -0500 (Wed, 03 Mar 2010)
New Revision: 18922
Removed:
annotations/branches/v3_3_1_GA_CP/common-build.xml
Log:
JBPAPP-3837 clean up build script
Deleted: annotations/branches/v3_3_1_GA_CP/common-build.xml
===================================================================
--- annotations/branches/v3_3_1_GA_CP/common-build.xml 2010-03-03 22:37:00 UTC (rev 18921)
+++ annotations/branches/v3_3_1_GA_CP/common-build.xml 2010-03-03 22:37:31 UTC (rev 18922)
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project name="common-build" default="dist">
- <property name="src.dir" location="src/java"/>
- <property name="test.dir" location="src/test"/>
- <property name="lib.dir" location="lib"/>
- <property name="build.dir" location="build"/>
-
- <property name="classes.dir" location="${build.dir}/classes"/>
- <property name="testclasses.dir" location="${build.dir}/testclasses"/>
- <property name="dist.target.dir" location="target"/>
- <property name="dist.dir" location="${build.dir}/${name}"/>
- <property name="instrumenttest.out.dir" value="instrumenttestout"/>
- <property name="doc.dir" location="doc"/>
- <property name="doc.api.dir" location="${doc.dir}/api"/>
- <property name="doc.reference.dir" location="${doc.dir}/reference"/>
-
- <property name="dist.doc.dir" location="${dist.dir}/doc"/>
- <property name="dist.api.dir" location="${dist.dir}/doc/api"/>
-
- <property name="dist.src.dir" location="${dist.dir}/src"/>
- <property name="dist.test.dir" location="${dist.dir}/test"/>
- <property name="dist.lib.dir" location="${dist.dir}/lib"/>
- <property name="jar.name" value="${name}"/>
- <property name="jar.file.name" value="${dist.dir}/${jar.name}.jar"/>
- <property name="jartest.file.name" value="${dist.dir}/${jar.name}-tests.jar"/>
- <property name="javac.debug" value="on"/>
- <property name="javac.optimize" value="off"/>
- <property name="javac.source" value="1.5"/>
- <property name="javac.target" value="1.5"/>
-
-
-
-
-
-
-
-
-
-
-
-</project>
\ No newline at end of file
14 years, 10 months