Hibernate SVN: r16491 - core/branches/Branch_3_3/testsuite.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-04-30 17:04:25 -0400 (Thu, 30 Apr 2009)
New Revision: 16491
Modified:
core/branches/Branch_3_3/testsuite/pom.xml
Log:
HHH-3886 - Fixed credentials for DB2
Modified: core/branches/Branch_3_3/testsuite/pom.xml
===================================================================
--- core/branches/Branch_3_3/testsuite/pom.xml 2009-04-30 14:22:42 UTC (rev 16490)
+++ core/branches/Branch_3_3/testsuite/pom.xml 2009-04-30 21:04:25 UTC (rev 16491)
@@ -214,7 +214,7 @@
<properties>
<db.dialect>org.hibernate.dialect.DB2Dialect</db.dialect>
<jdbc.driver>com.ibm.db2.jcc.DB2Driver</jdbc.driver>
- <jdbc.url>jdbc:db2://dev32.qa.atl.jboss.com:50000/hibbr330</jdbc.url>
+ <jdbc.url>jdbc:db2://dev32.qa.atl.jboss.com:50000/jbossqa</jdbc.url>
<jdbc.user>hibbr330</jdbc.user>
<jdbc.pass>hibbr330</jdbc.pass>
<jdbc.isolation />
@@ -239,7 +239,7 @@
<properties>
<db.dialect>org.hibernate.dialect.DB2Dialect</db.dialect>
<jdbc.driver>com.ibm.db2.jcc.DB2Driver</jdbc.driver>
- <jdbc.url>jdbc:db2://dev67.qa.atl.jboss.com:50000/hibbr330</jdbc.url>
+ <jdbc.url>jdbc:db2://dev67.qa.atl.jboss.com:50000/jbossqa</jdbc.url>
<jdbc.user>hibbr330</jdbc.user>
<jdbc.pass>hibbr330</jdbc.pass>
<jdbc.isolation />
15 years, 8 months
Hibernate SVN: r16490 - search/trunk.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-04-30 10:22:42 -0400 (Thu, 30 Apr 2009)
New Revision: 16490
Modified:
search/trunk/pom.xml
Log:
HSEARCH-365 - Added QA Lab database profiles
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2009-04-30 11:51:02 UTC (rev 16489)
+++ search/trunk/pom.xml 2009-04-30 14:22:42 UTC (rev 16490)
@@ -323,7 +323,193 @@
</properties>
</profile>
+ <!--
+ ###################################################################
+ Profiles naming db instances in the Red Hat QA/QE lab
+ First, those with OSS drivers
+ ###################################################################
+ -->
+
+ <!-- The MySQL5 test envionment -->
+ <profile>
+ <id>mysql5</id>
+ <dependencies>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.0.5</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <db.dialect>org.hibernate.dialect.MySQL5InnoDBDialect</db.dialect>
+ <jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
+ <jdbc.url>jdbc:mysql://dev02.qa.atl.jboss.com/hibbrtru</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation />
+ </properties>
+ </profile>
+
+ <!-- The PostgreSQL test envionment -->
+ <profile>
+ <id>postgresql823</id>
+ <dependencies>
+ <dependency>
+ <groupId>postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>8.2-504</version>
+ <classifier>jdbc3</classifier>
+ </dependency>
+ </dependencies>
+ <properties>
+ <db.dialect>org.hibernate.dialect.PostgreSQLDialect</db.dialect>
+ <jdbc.driver>org.postgresql.Driver</jdbc.driver>
+ <jdbc.url>jdbc:postgresql://dev01.qa.atl.jboss.com:5432:hibbrtru</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation />
+ </properties>
+ </profile>
+
+ <!--
+ ###################################################################
+ Then, those with commercial drivers
+ ###################################################################
+ -->
+
+ <!-- The DB2 8.x test envionment (using 9x drivers)-->
+ <profile>
+ <id>db2v82</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.ibm</groupId>
+ <artifactId>db2jcc</artifactId>
+ <version>3.1.57</version>
+ </dependency>
+ <dependency>
+ <groupId>com.ibm</groupId>
+ <artifactId>db2jcc_license_cu</artifactId>
+ <version>3.1.57</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <db.dialect>org.hibernate.dialect.DB2Dialect</db.dialect>
+ <jdbc.driver>com.ibm.db2.jcc.DB2Driver</jdbc.driver>
+ <jdbc.url>jdbc:db2://dev32.qa.atl.jboss.com:50000/hibbrtru</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation />
+ </properties>
+ </profile>
+
+ <!-- The DB2 9.x test envionment (using 9x drivers)-->
+ <profile>
+ <id>db2v91</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.ibm</groupId>
+ <artifactId>db2jcc</artifactId>
+ <version>3.1.57</version>
+ </dependency>
+ <dependency>
+ <groupId>com.ibm</groupId>
+ <artifactId>db2jcc_license_cu</artifactId>
+ <version>3.1.57</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <db.dialect>org.hibernate.dialect.DB2Dialect</db.dialect>
+ <jdbc.driver>com.ibm.db2.jcc.DB2Driver</jdbc.driver>
+ <jdbc.url>jdbc:db2://dev67.qa.atl.jboss.com:50000/hibbrtru</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation />
+ </properties>
+ </profile>
+
+ <!-- The Oracle9i test envionment -->
+ <profile>
+ <id>oracle9i</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.oracle</groupId>
+ <artifactId>ojdbc14</artifactId>
+ <!-- use the 10g drivers which are surprisingly largely bug free -->
+ <version>10.0.2.0</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <db.dialect>org.hibernate.dialect.Oracle9iDialect</db.dialect>
+ <jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
+ <jdbc.url>jdbc:oracle:thin:@dev20.qa.atl.jboss.com:1521:qa</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation />
+ </properties>
+ </profile>
+
+ <!-- The Oracle10g test envionment -->
+ <profile>
+ <id>oracle10g</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.oracle</groupId>
+ <artifactId>ojdbc14</artifactId>
+ <!-- use the 10g drivers which are surprisingly largely bug free -->
+ <version>10.0.2.0</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
+ <jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
+ <jdbc.url>jdbc:oracle:thin:@dev01.qa.atl.jboss.com:1521:qadb01</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation />
+ </properties>
+ </profile>
+
+ <!-- The Sybase 15 test envionment -->
+ <profile>
+ <id>sybase15</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.sybase</groupId>
+ <artifactId>jconnect</artifactId>
+ <version>6.0.5</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <db.dialect>org.hibernate.dialect.SybaseASE15Dialect</db.dialect>
+ <jdbc.driver>com.sybase.jdbc3.jdbc.SybDriver</jdbc.driver>
+ <jdbc.url>jdbc:sybase:Tds:dev77.qa.atl2.redhat.com:5000/hibbrtru</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation />
+ </properties>
+ </profile>
+
+ <!-- The SQLServer2005 (MS JDBC) test envionment -->
+ <profile>
+ <id>mssql2005</id>
+ <dependencies>
+ <dependency>
+ <groupId>com.microsoft.sqlserver</groupId>
+ <artifactId>msjdbc</artifactId>
+ <version>1.1</version>
+ </dependency>
+ </dependencies>
+ <properties>
+ <db.dialect>org.hibernate.dialect.SQLServerDialect</db.dialect>
+ <jdbc.driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbc.driver>
+ <jdbc.url>jdbc:sqlserver://dev30.qa.atl.jboss.com:3918</jdbc.url>
+ <jdbc.user>hibbrtru</jdbc.user>
+ <jdbc.pass>hibbrtru</jdbc.pass>
+ <jdbc.isolation>4096</jdbc.isolation>
+ </properties>
+ </profile>
+
<!-- ================================ -->
<!-- Dependecy profiles to test w and -->
<!-- w/o optional dependencies -->
15 years, 8 months
Hibernate SVN: r16489 - branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-04-30 07:51:02 -0400 (Thu, 30 Apr 2009)
New Revision: 16489
Modified:
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/QueryTest.java
Log:
EJB-403 - Removed alias from native update statement, as it is not supported in many databases.
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/QueryTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/QueryTest.java 2009-04-30 11:48:05 UTC (rev 16488)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/QueryTest.java 2009-04-30 11:51:02 UTC (rev 16489)
@@ -51,7 +51,7 @@
public void testParameterList() throws Exception {
final Item item = new Item( "Mouse", "Micro$oft mouse" );
- final Item item2 = new Item( "Computer", "D�ll computer" );
+ final Item item2 = new Item( "Computer", "D�ll computer" );
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
@@ -120,7 +120,7 @@
public void testEscapeCharacter() throws Exception {
final Item item = new Item( "Mouse", "Micro_oft mouse" );
- final Item item2 = new Item( "Computer", "D�ll computer" );
+ final Item item2 = new Item( "Computer", "D�ll computer" );
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
@@ -331,7 +331,7 @@
assertEquals(
1, em.createNativeQuery(
- "update Item i set i.descr = 'Logitech Mouse' where i.name = 'Mouse'"
+ "update Item set descr = 'Logitech Mouse' where name = 'Mouse'"
).executeUpdate()
);
item = em.find( Item.class, item.getName() );
15 years, 8 months
Hibernate SVN: r16488 - in branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test: association and 11 other directories.
by hibernate-commits@lists.jboss.org
Author: jcosta(a)redhat.com
Date: 2009-04-30 07:48:05 -0400 (Thu, 30 Apr 2009)
New Revision: 16488
Modified:
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/EntityManagerTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/QueryTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/TestCase.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ValidatorIntegrationTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/association/AssociationTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/CascadeTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/FetchTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/FetchTest2.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/MergeTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/RefreshTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/RemoveTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/inheritance/InheritanceTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lob/BlobTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/LockTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ops/FindTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ops/MergeNewTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java
branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/xml/XmlTest.java
Log:
EJB-430 - Applied patch to avoid locking transactions when exceptions occurs in EM tests
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/EntityManagerTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/EntityManagerTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/EntityManagerTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -49,7 +49,7 @@
//
// Item item = new Item( "Mouse", "Micro$oft mouse" );
//
-// EntityManager em = factory.createEntityManager();
+// EntityManager em = getOrCreateEntityManager();
// em.getTransaction().begin();
// em.persist( item );
// assertTrue( em.contains( item ) );
@@ -95,7 +95,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -148,7 +148,7 @@
stats.clear();
stats.setStatisticsEnabled( true );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( res );
@@ -161,7 +161,7 @@
assertEquals( 1, stats.getSecondLevelCachePutCount() );
assertEquals( 0, stats.getSecondLevelCacheHitCount() );
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Item second = em.find( Item.class, item.getName() );
assertEquals( 1, second.getDistributors().size() );
@@ -169,7 +169,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
second = em.find( Item.class, item.getName() );
assertEquals( 1, second.getDistributors().size() );
@@ -184,7 +184,7 @@
}
public void testContains() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Integer nonManagedObject = new Integer( 4 );
try {
@@ -198,7 +198,7 @@
finally {
em.close();
}
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Item item = new Item();
item.setDescr( "Mine" );
@@ -214,7 +214,7 @@
}
public void testClear() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand( "Lacoste" );
@@ -229,7 +229,7 @@
}
public void testFlushMode() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.setFlushMode( FlushModeType.COMMIT );
assertEquals( FlushModeType.COMMIT, em.getFlushMode() );
( (HibernateEntityManager) em ).getSession().setFlushMode( FlushMode.ALWAYS );
@@ -238,7 +238,7 @@
}
public void testPersistNoneGenerator() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand( "Lacoste" );
@@ -255,7 +255,7 @@
}
public void testSerializableException() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
Query query = em.createQuery( "SELECT p FETCH JOIN p.distributors FROM Item p" );
@@ -297,7 +297,7 @@
}
public void testIsOpen() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
assertTrue( em.isOpen() );
em.getTransaction().begin();
assertTrue( em.isOpen() );
@@ -308,7 +308,7 @@
//EJB-9
// public void testGet() throws Exception {
-// EntityManager em = factory.createEntityManager();
+// EntityManager em = getOrCreateEntityManager();
// em.getTransaction().begin();
// Item item = (Item) em.get(Item.class, "nonexistentone");
// try {
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/PackagedEntityManagerTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -245,7 +245,7 @@
//
// Item item = new Item( "Mouse", "Micro$oft mouse" );
//
-// EntityManager em = factory.createEntityManager();
+// EntityManager em = getOrCreateEntityManager();
// em.getTransaction().begin();
// em.persist( item );
// assertTrue( em.contains( item ) );
@@ -294,7 +294,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -347,7 +347,7 @@
stats.clear();
stats.setStatisticsEnabled( true );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( res );
@@ -360,7 +360,7 @@
assertEquals( 1, stats.getSecondLevelCachePutCount() );
assertEquals( 0, stats.getSecondLevelCacheHitCount() );
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Item second = em.find( Item.class, item.getName() );
assertEquals( 1, second.getDistributors().size() );
@@ -368,7 +368,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
second = em.find( Item.class, item.getName() );
assertEquals( 1, second.getDistributors().size() );
@@ -385,7 +385,7 @@
}
public void testExternalJar() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Scooter s = new Scooter();
s.setModel( "Abadah" );
s.setSpeed( 85l );
@@ -393,7 +393,7 @@
em.persist( s );
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
s = em.find( Scooter.class, s.getModel() );
assertEquals( new Long( 85 ), s.getSpeed() );
@@ -403,7 +403,7 @@
}
public void testORMFileOnMainAndExplicitJars() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Seat seat = new Seat();
seat.setNumber( "3B" );
Airplane plane = new Airplane();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/QueryTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/QueryTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/QueryTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -17,7 +17,7 @@
public class QueryTest extends TestCase {
public void testPagedQuery() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Item item = new Item( "Mouse", "Micro$oft mouse" );
em.persist( item );
@@ -36,7 +36,7 @@
}
public void testAggregationReturnType() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Item item = new Item( "Mouse", "Micro$oft mouse" );
em.persist( item );
@@ -53,7 +53,7 @@
final Item item = new Item( "Mouse", "Micro$oft mouse" );
final Item item2 = new Item( "Computer", "D�ll computer" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
em.persist( item2 );
@@ -94,7 +94,7 @@
// auchan.setName("Auchan");
// item.addDistributor(auchan);
//
-// EntityManager em = factory.createEntityManager();
+// EntityManager em = getOrCreateEntityManager();
// em.getTransaction().begin();
// em.persist(fnac);
// em.persist(auchan);
@@ -122,7 +122,7 @@
final Item item = new Item( "Mouse", "Micro_oft mouse" );
final Item item2 = new Item( "Computer", "D�ll computer" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
em.persist( item2 );
@@ -145,7 +145,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -166,7 +166,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -185,7 +185,7 @@
}
public void testExplicitPositionalParameter() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand( "Lacoste" );
@@ -210,7 +210,7 @@
}
public void testNativeQuestionMarkParameter() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Wallet w = new Wallet();
w.setBrand( "Lacoste" );
@@ -232,7 +232,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
@@ -257,7 +257,7 @@
}
public void testDistinct() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.createQuery( "delete Item" ).executeUpdate();
em.createQuery( "delete Distributor" ).executeUpdate();
@@ -285,7 +285,7 @@
}
public void testIsNull() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Distributor d1 = new Distributor();
d1.setName( "Fnac" );
@@ -321,7 +321,7 @@
Item item = new Item( "Mouse", "Micro$oft mouse" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( item );
assertTrue( em.contains( item ) );
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/TestCase.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/TestCase.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/TestCase.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -7,10 +7,15 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+
+import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.Dialect;
import org.hibernate.ejb.HibernatePersistence;
@@ -19,6 +24,8 @@
*/
public abstract class TestCase extends junit.framework.TestCase {
protected EntityManagerFactory factory;
+ protected EntityManager em;
+ private static Log log = LogFactory.getLog( TestCase.class );
public TestCase() {
super();
@@ -35,7 +42,39 @@
public void tearDown() {
factory.close();
}
+
+ @Override
+ public void runTest() throws Throwable {
+ try {
+ em = getOrCreateEntityManager();
+ super.runTest();
+ } catch (Throwable t) {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
+ throw t;
+ } finally {
+ if (em.isOpen()) {
+ em.close();
+ log.warn("The test case didn't closed the Entity Manager. Make sure you close it always!");
+ }
+ }
+ }
+
+ protected EntityManager getOrCreateEntityManager() {
+ if (em == null || !em.isOpen())
+ em = factory.createEntityManager();
+ return em;
+ }
+ /** always reopen a new EM and clse the existing one */
+ protected EntityManager createEntityManager(Map properties) {
+ if (em != null && em.isOpen() ) {
+ em.close();
+ }
+ em = factory.createEntityManager(properties);
+ return em;
+ }
+
public abstract Class[] getAnnotatedClasses();
public String[] getEjb3DD() {
@@ -101,4 +140,33 @@
}
return config;
}
+
+ @Override
+ public void runBare() throws Throwable {
+
+ if (!appliesTo(Dialect.getDialect()))
+ return;
+
+ Throwable exception = null;
+ setUp();
+ try {
+ runTest();
+ } catch (Throwable running) {
+ exception = running;
+ } finally {
+ try {
+ tearDown();
+ } catch (Throwable tearingDown) {
+ if (exception == null)
+ exception = tearingDown;
+ }
+ }
+ if (exception != null)
+ throw exception;
+ }
+
+ public boolean appliesTo(Dialect dialect) {
+ return true;
+ }
+
}
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ValidatorIntegrationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ValidatorIntegrationTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ValidatorIntegrationTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -12,7 +12,7 @@
public class ValidatorIntegrationTest extends TestCase {
public void testPropertyValidation() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Cat cat = new Cat();
cat.setAge( 33 );
cat.setDateOfBirth( new Date() );
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/association/AssociationTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/association/AssociationTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/association/AssociationTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -10,7 +10,7 @@
*/
public class AssociationTest extends TestCase {
public void testBidirOneToOne() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
String id = "10";
Incident i = em.find( Incident.class, id );
@@ -30,7 +30,7 @@
}
public void testMergeAndBidirOneToOne() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Oven oven = new Oven();
Kitchen kitchen = new Kitchen();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/callbacks/CallbackAndDirtyTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -13,7 +13,7 @@
public class CallbackAndDirtyTest extends TestCase {
public void testDirtyButNotDirty() throws Exception {
- EntityManager manager = factory.createEntityManager();
+ EntityManager manager = getOrCreateEntityManager();
manager.getTransaction().begin();
Employee mark = new Employee();
mark.setName( "Mark" );
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/callbacks/CallbacksTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -14,7 +14,7 @@
public class CallbacksTest extends TestCase {
public void testCallbackMethod() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
c.setName( "Kitty" );
c.setDateOfBirth( new Date( 90, 11, 15 ) );
@@ -36,7 +36,7 @@
}
public void testEntityListener() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
c.setName( "Kitty" );
c.setLength( 12 );
@@ -63,7 +63,7 @@
public void testPostPersist() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Cat c = new Cat();
em.getTransaction().begin();
c.setLength( 23 );
@@ -80,7 +80,7 @@
//Not a test since the spec did not make the proper change on listeners
public void listenerAnnotation() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Translation tl = new Translation();
em.getTransaction().begin();
tl.setInto( "France" );
@@ -102,7 +102,7 @@
}
public void testPrePersistOnCascade() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Television tv = new Television();
RemoteControl rc = new RemoteControl();
@@ -116,7 +116,7 @@
}
public void testCallBackListenersHierarchy() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Television tv = new Television();
em.persist( tv );
@@ -131,7 +131,7 @@
}
public void testException() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Rythm r = new Rythm();
try {
@@ -154,7 +154,7 @@
public void testIdNullSetByPrePersist() throws Exception {
Plant plant = new Plant();
plant.setName( "Origuna plantula gigantic" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( plant );
em.flush();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/CascadeTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/CascadeTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/CascadeTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -14,7 +14,7 @@
public void testCascade() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Teacher teacher = null;
@@ -33,7 +33,7 @@
em.getTransaction().commit();
System.out.println("***************************");
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Teacher foundTeacher = (Teacher) em.createQuery( "select t from Teacher as t" ).getSingleResult();
@@ -59,7 +59,7 @@
e1.setAuthor(e2);
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(e2);
@@ -67,7 +67,7 @@
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
e1 = em.find(Song.class, e1.getId());
e2 = null;
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/DeleteOrphanTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -20,7 +20,7 @@
public void testDeleteOrphan() throws Exception {
EntityTransaction tx;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Troop disney = new Troop();
@@ -33,7 +33,7 @@
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Troop troop = em.find( Troop.class, disney.getId() );
@@ -45,14 +45,14 @@
troop.getSoldiers().remove( soldier );
troop = (Troop) unserialize( serialize( troop ) );
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
em.merge( troop );
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
soldier = em.find( Soldier.class, mickey.getId() );
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/FetchTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/FetchTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/FetchTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -17,7 +17,7 @@
public class FetchTest extends TestCase {
public void testCascadeAndFetchCollection() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop disney = new Troop();
disney.setName( "Disney" );
@@ -28,7 +28,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop troop = em.find( Troop.class, disney.getId() );
assertFalse( Hibernate.isInitialized( troop.getSoldiers() ) );
@@ -36,7 +36,7 @@
assertFalse( Hibernate.isInitialized( troop.getSoldiers() ) );
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
troop = em.find( Troop.class, disney.getId() );
em.remove( troop );
@@ -46,7 +46,7 @@
}
public void testCascadeAndFetchEntity() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop disney = new Troop();
disney.setName( "Disney" );
@@ -57,14 +57,14 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Soldier soldier = em.find( Soldier.class, mickey.getId() );
assertFalse( Hibernate.isInitialized( soldier.getTroop() ) );
em.getTransaction().commit();
assertFalse( Hibernate.isInitialized( soldier.getTroop() ) );
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop troop = em.find( Troop.class, disney.getId() );
em.remove( troop );
@@ -76,7 +76,7 @@
public void testTwoLevelDeepPersist() throws Exception {
EntityTransaction tx;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Conference jbwBarcelona = new Conference();
@@ -94,7 +94,7 @@
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
jbwBarcelona = em.find( Conference.class, jbwBarcelona.getId() );
@@ -112,7 +112,7 @@
public void testTwoLevelDeepPersistOnManyToOne() throws Exception {
EntityTransaction tx;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
Grandson gs = new Grandson();
@@ -121,7 +121,7 @@
em.persist( gs );
tx.commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
tx = em.getTransaction();
tx.begin();
gs = em.find( Grandson.class, gs.getId() );
@@ -134,7 +134,7 @@
}
public void testPerfCascadeAndFetchEntity() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
//init data
em.getTransaction().begin();
int loop = 50;
@@ -150,7 +150,7 @@
em.close();
//Warm up loop
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
for ( int i = 0; i < loop ; i++ ) {
//Soldier soldier = em.find( Soldier.class, new Integer(i) );
@@ -167,7 +167,7 @@
//do not evict
for ( int j = 0; j < 10 ; j++ ) {
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
for ( int i = 0; i < loop ; i++ ) {
Troop troop = em.find( Troop.class, new Integer( i ) );
@@ -182,7 +182,7 @@
em.close();
//evict
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
for ( int i = 0; i < loop ; i++ ) {
//Soldier soldier = em.find( Soldier.class, new Integer(i) );
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/FetchTest2.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/FetchTest2.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/cascade/FetchTest2.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -8,7 +8,7 @@
public void testProxyTransientStuff() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Troop2 disney = new Troop2();
@@ -24,7 +24,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Soldier2 soldier = em.find( Soldier2.class, mickey.getId() );
@@ -39,7 +39,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
//load troop wo a proxy
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/FlushTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -26,7 +26,7 @@
//Test for EJBTHREE-722
public void testFlushOnDetached() throws Exception {
- EntityManager manager = factory.createEntityManager( );
+ EntityManager manager = getOrCreateEntityManager( );
manager.getTransaction().begin();
Pet p1 = createCat("Toonses", 15.0, 9, manager);
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/GetReferenceTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -12,7 +12,7 @@
public class GetReferenceTest extends TestCase {
public void testWrongIdType() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
try {
Competitor c = em.getReference( Competitor.class, new String("30") );
fail("Expected IllegalArgumentException");
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/MergeTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/MergeTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -16,7 +16,7 @@
race.competitors.add( new Competitor("Name") );
race.competitors.add( new Competitor() );
race.competitors.add( new Competitor() );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.flush();
@@ -40,7 +40,7 @@
competition.getCompetitors().add( new Competitor("Name") );
competition.getCompetitors().add( new Competitor() );
competition.getCompetitors().add( new Competitor() );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( competition );
em.flush();
@@ -64,7 +64,7 @@
competition.getCompetitors().add( new Competitor("Name") );
competition.getCompetitors().add( new Competitor() );
competition.getCompetitors().add( new Competitor() );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( competition );
em.flush();
@@ -86,7 +86,7 @@
public void testRemoveAndMerge() {
Race race = new Race();
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.flush();
@@ -111,7 +111,7 @@
public void testConcurrentMerge() {
Race race = new Race();
race.name = "Derby";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.flush();
@@ -120,7 +120,7 @@
race.name = "Magnicourt";
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
Race race2 = em.find(Race.class, race.id );
race2.name = "Mans";
@@ -130,7 +130,7 @@
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
race2 = em.find(Race.class, race.id );
assertEquals( "Last commit win in merge", "Magnicourt", race2.name );
@@ -141,7 +141,7 @@
}
public void testMergeUnidirectionalOneToMany() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Empire roman = new Empire();
em.persist( roman );
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/RefreshTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/RefreshTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/RefreshTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -11,7 +11,7 @@
public class RefreshTest extends TestCase {
public void testRefreshNonManaged() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Race race = new Race();
em.persist( race );
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/RemoveTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/RemoveTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/RemoveTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -16,7 +16,7 @@
race.competitors.add( new Competitor() );
race.competitors.add( new Competitor() );
race.competitors.add( new Competitor() );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.flush();
@@ -28,7 +28,7 @@
public void testRemoveAndFind() {
Race race = new Race();
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( race );
em.remove( race );
@@ -40,14 +40,14 @@
public void testUpdatedAndRemove() {
Music music = new Music();
music.setName( "Classical" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( music );
em.getTransaction().commit();
em.clear();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
EntityManager em2 = factory.createEntityManager();
em2.getTransaction().begin();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/emops/cascade/CascadePersistTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -13,7 +13,7 @@
public class CascadePersistTest extends TestCase {
public void testLazyCollectionsStayLazyOnPersist() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
//initialize
A a = new A();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/exception/ExceptionTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -15,7 +15,7 @@
public class ExceptionTest extends TestCase {
public void testOptimisticLockingException() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
EntityManager em2 = factory.createEntityManager();
em.getTransaction().begin();
Music music = new Music();
@@ -50,7 +50,7 @@
}
public void testEntityNotFoundException() throws Exception {
- EntityManager em = factory.createEntityManager( );
+ EntityManager em = getOrCreateEntityManager( );
Music music = em.getReference( Music.class, new Integer(-1) );
try {
music.getName();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/inheritance/InheritanceTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/inheritance/InheritanceTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/inheritance/InheritanceTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -11,7 +11,7 @@
public class InheritanceTest extends TestCase {
public void testFind() throws Exception {
- EntityManager firstSession = factory.createEntityManager( );
+ EntityManager firstSession = getOrCreateEntityManager( );
Strawberry u = new Strawberry();
u.setSize( 12l );
firstSession.getTransaction().begin();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lob/BlobTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lob/BlobTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lob/BlobTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -18,7 +18,7 @@
public class BlobTest extends TestCase {
public void testBlobSerialization() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Map image = new HashMap();
image.put( "meta", "metadata" );
@@ -31,7 +31,7 @@
em.persist( reader );
em.getTransaction().commit();
em.close(); //useless but y'a know
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
reader = em.find( ImageReader.class, reader.getId() );
ObjectInputStream ois = new ObjectInputStream( reader.getImage().getBinaryStream() );
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/LockTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/LockTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/lock/LockTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -14,7 +14,7 @@
public void testLockRead() throws Exception {
Lock lock = new Lock();
lock.setName( "name" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( lock );
em.getTransaction().commit();
@@ -35,7 +35,7 @@
public void testLockWrite() throws Exception {
Lock lock = new Lock();
lock.setName( "second" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( lock );
em.getTransaction().commit();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ops/FindTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ops/FindTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ops/FindTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -14,7 +14,7 @@
Mammal mammal = new Mammal();
mammal.setMamalNbr( 2 );
mammal.setName( "Human" );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( mammal );
em.flush();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ops/MergeNewTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ops/MergeNewTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/ops/MergeNewTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -14,7 +14,7 @@
Workload load = new Workload();
load.name = "Cleaning";
load.load = 10;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
load = em.merge( load );
assertNotNull( load.id );
@@ -28,20 +28,20 @@
Workload load = new Workload();
load.name = "Cleaning";
load.load = 10;
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
load = em.merge( load );
em.flush();
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
load = em.find( Workload.class, load.id );
em.remove( load );
em.flush();
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
em.merge( load );
em.flush();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/transaction/FlushAndTransactionTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -21,7 +21,7 @@
public void testAlwaysTransactionalOperations() throws Exception {
Book book = new Book();
book.name = "Le petit prince";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( book );
em.getTransaction().commit();
@@ -47,7 +47,7 @@
// public void testTransactionalOperationsWhenTransactional() throws Exception {
// Book book = new Book();
// book.name = "Le petit prince";
-// EntityManager em = factory.createEntityManager( PersistenceContextType.TRANSACTION );
+// EntityManager em = getOrCreateEntityManager( PersistenceContextType.TRANSACTION );
// try {
// em.persist( book );
// fail("flush has to be inside a Tx");
@@ -75,7 +75,7 @@
public void testTransactionalOperationsWhenExtended() throws Exception {
Book book = new Book();
book.name = "Le petit prince";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Statistics stats = ( (HibernateEntityManagerFactory) factory ).getSessionFactory().getStatistics();
stats.clear();
stats.setStatisticsEnabled( true );
@@ -118,7 +118,7 @@
public void testMergeWhenExtended() throws Exception {
Book book = new Book();
book.name = "Le petit prince";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
Statistics stats = ( (HibernateEntityManagerFactory) factory ).getSessionFactory().getStatistics();
em.getTransaction().begin();
@@ -159,7 +159,7 @@
}
public void testCloseAndTransaction() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Book book = new Book();
book.name = "Java for Dummies";
@@ -176,7 +176,7 @@
}
em.getTransaction().commit();
assertFalse( em.isOpen() );
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
book = em.find( Book.class, book.id );
assertEquals( "C# for Dummies", book.name );
@@ -186,14 +186,14 @@
}
public void testTransactionCommitDoesNotFlush() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Book book = new Book();
book.name = "Java for Dummies";
em.persist( book );
em.getTransaction().commit();
em.close();
- em = factory.createEntityManager();
+ em = getOrCreateEntityManager();
em.getTransaction().begin();
List result = em.createQuery("select book from Book book where book.name = :title").
setParameter( "title", book.name ).getResultList();
@@ -206,7 +206,7 @@
Book book = new Book();
book.name = "Stolen keys";
book.id = null; //new Integer( 50 );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
try {
em.persist( book );
@@ -241,7 +241,7 @@
Book book = new Book();
book.name = "Stolen keys";
book.id = null; //new Integer( 50 );
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( book );
em.flush();
@@ -268,7 +268,7 @@
public void testRollbackClearPC() throws Exception {
Book book = new Book();
book.name = "Stolen keys";
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist( book );
em.getTransaction().commit();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/xml/XmlAttributeOverrideTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -11,7 +11,7 @@
public class XmlAttributeOverrideTest extends TestCase {
public void testAttributeOverriding() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
Employee e = new Employee();
Modified: branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/xml/XmlTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/xml/XmlTest.java 2009-04-30 08:39:38 UTC (rev 16487)
+++ branches/Branch_3_2/HibernateExt/entitymanager/src/test/org/hibernate/ejb/test/xml/XmlTest.java 2009-04-30 11:48:05 UTC (rev 16488)
@@ -10,7 +10,7 @@
*/
public class XmlTest extends TestCase {
public void testXmlMappingCorrectness() throws Exception {
- EntityManager em = factory.createEntityManager();
+ EntityManager em = getOrCreateEntityManager();
em.close();
}
15 years, 8 months
Hibernate SVN: r16487 - in core/trunk/envers/src: test/java/org/hibernate/envers/test/entities and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-04-30 04:39:38 -0400 (Thu, 30 Apr 2009)
New Revision: 16487
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/PrimitiveTestEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/primitive/
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/primitive/PrimitiveAddDelete.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java
core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-3878:
- fixing reading deleted entities with null-only values, when the field is primitive
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java 2009-04-30 07:42:39 UTC (rev 16486)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/SinglePropertyMapper.java 2009-04-30 08:39:38 UTC (rev 16487)
@@ -36,7 +36,9 @@
import org.hibernate.collection.PersistentCollection;
import org.hibernate.property.Setter;
+import org.hibernate.property.DirectPropertyAccessor;
import org.hibernate.engine.SessionImplementor;
+import org.hibernate.HibernateException;
/**
* TODO: diff
@@ -68,9 +70,27 @@
}
Setter setter = ReflectionTools.getSetter(obj.getClass(), propertyData);
- setter.set(obj, data.get(propertyData.getName()), null);
+ Object value = data.get(propertyData.getName());
+ // We only set a null value if the field is not primite. Otherwise, we leave it intact.
+ if (value != null || !isPrimitive(setter, propertyData, obj.getClass())) {
+ setter.set(obj, value, null);
+ }
}
+ private boolean isPrimitive(Setter setter, PropertyData propertyData, Class<?> cls) {
+ if (setter instanceof DirectPropertyAccessor.DirectSetter) {
+ // In a direct setter, getMethod() returns null
+ // Trying to look up the field
+ try {
+ return cls.getDeclaredField(propertyData.getBeanName()).getType().isPrimitive();
+ } catch (NoSuchFieldException e) {
+ throw new HibernateException(e);
+ }
+ } else {
+ return setter.getMethod().getParameterTypes()[0].isPrimitive();
+ }
+ }
+
public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/PrimitiveTestEntity.java (from rev 16482, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/IntTestEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/PrimitiveTestEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/PrimitiveTestEntity.java 2009-04-30 08:39:38 UTC (rev 16487)
@@ -0,0 +1,109 @@
+/*
+ * 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.envers.test.entities;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class PrimitiveTestEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Audited
+ private int number;
+
+ private int number2;
+
+ public PrimitiveTestEntity() {
+ }
+
+ public PrimitiveTestEntity(int number, int number2) {
+ this.number = number;
+ this.number2 = number2;
+ }
+
+ public PrimitiveTestEntity(Integer id, int number, int number2) {
+ this.id = id;
+ this.number = number;
+ this.number2 = number2;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Integer getNumber() {
+ return number;
+ }
+
+ public void setNumber(Integer number) {
+ this.number = number;
+ }
+
+ public int getNumber2() {
+ return number2;
+ }
+
+ public void setNumber2(int number2) {
+ this.number2 = number2;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof PrimitiveTestEntity)) return false;
+
+ PrimitiveTestEntity that = (PrimitiveTestEntity) o;
+
+ if (number != that.number) return false;
+ if (number2 != that.number2) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = id != null ? id.hashCode() : 0;
+ result = 31 * result + number;
+ result = 31 * result + number2;
+ return result;
+ }
+
+ public String toString() {
+ return "PTE(id = " + id + ", number = " + number + ", number2 = " + number2 + ")";
+ }
+}
\ No newline at end of file
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/primitive/PrimitiveAddDelete.java (from rev 16482, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/basic/Simple.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/primitive/PrimitiveAddDelete.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/primitive/PrimitiveAddDelete.java 2009-04-30 08:39:38 UTC (rev 16487)
@@ -0,0 +1,97 @@
+/*
+ * 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.envers.test.integration.primitive;
+
+import java.util.Arrays;
+import java.util.List;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.PrimitiveTestEntity;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class PrimitiveAddDelete extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(PrimitiveTestEntity.class);
+ }
+
+ @Test
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ // Revision 1
+ em.getTransaction().begin();
+ PrimitiveTestEntity pte = new PrimitiveTestEntity(10, 11);
+ em.persist(pte);
+ id1 = pte.getId();
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+ pte = em.find(PrimitiveTestEntity.class, id1);
+ pte.setNumber(20);
+ pte.setNumber2(21);
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+ pte = em.find(PrimitiveTestEntity.class, id1);
+ em.remove(pte);
+ em.getTransaction().commit();
+ }
+
+ @Test(dependsOnMethods = "initData")
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 3).equals(getAuditReader().getRevisions(PrimitiveTestEntity.class, id1));
+ }
+
+ @Test(dependsOnMethods = "initData")
+ public void testHistoryOfId1() {
+ PrimitiveTestEntity ver1 = new PrimitiveTestEntity(id1, 10, 0);
+ PrimitiveTestEntity ver2 = new PrimitiveTestEntity(id1, 20, 0);
+
+ assert getAuditReader().find(PrimitiveTestEntity.class, id1, 1).equals(ver1);
+ assert getAuditReader().find(PrimitiveTestEntity.class, id1, 2).equals(ver2);
+ assert getAuditReader().find(PrimitiveTestEntity.class, id1, 3) == null;
+ }
+
+ @Test(dependsOnMethods = "initData")
+ public void testQueryWithDeleted() {
+ // Selecting all entities, also the deleted ones
+ List entities = getAuditReader().createQuery().forRevisionsOfEntity(PrimitiveTestEntity.class, true, true)
+ .getResultList();
+
+ assert entities.size() == 3;
+ assert entities.get(0).equals(new PrimitiveTestEntity(id1, 10, 0));
+ assert entities.get(1).equals(new PrimitiveTestEntity(id1, 20, 0));
+ assert entities.get(2).equals(new PrimitiveTestEntity(id1, 0, 0));
+ }
+}
\ No newline at end of file
Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml 2009-04-30 07:42:39 UTC (rev 16486)
+++ core/trunk/envers/src/test/resources/testng.xml 2009-04-30 08:39:38 UTC (rev 16487)
@@ -42,6 +42,7 @@
<package name="org.hibernate.envers.test.integration.onetoone.bidirectional" />
<package name="org.hibernate.envers.test.integration.onetoone.bidirectional.ids" />
<package name="org.hibernate.envers.test.integration.onetoone.unidirectional" />
+ <package name="org.hibernate.envers.test.integration.primitive" />
<package name="org.hibernate.envers.test.integration.properties" />
<package name="org.hibernate.envers.test.integration.query" />
<package name="org.hibernate.envers.test.integration.query.ids" />
15 years, 8 months
Hibernate SVN: r16486 - core/trunk/documentation/envers/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-04-30 03:42:39 -0400 (Thu, 30 Apr 2009)
New Revision: 16486
Modified:
core/trunk/documentation/envers/src/main/docbook/en-US/content/revisionlog.xml
Log:
HHH-3823:
- updating documentation
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/revisionlog.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/revisionlog.xml 2009-04-30 07:36:14 UTC (rev 16485)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/revisionlog.xml 2009-04-30 07:42:39 UTC (rev 16486)
@@ -70,6 +70,17 @@
</para>
<para>
+ Alternatively, you can use the <literal>getCurrentRevision</literal> method of the
+ <literal>AuditReader</literal> interface to obtain the current revision, and fill it with desired information.
+ The method has a <literal>persist</literal> parameter specifying, if the revision entity should be persisted
+ before returning. If set to <literal>true</literal>, the revision number will be available in the returned
+ revision entity (as it is normally generated by the database), but the revision entity will be persisted
+ regardless of wheter there are any audited entities changed. If set to <literal>false</literal>, the revision
+ number will be <literal>null</literal>, but the revision entity will be persisted only if some audited entities
+ have changed.
+ </para>
+
+ <para>
A simplest example of a revisions entity, which with each revision associates the
username of the user making the change is:
</para>
15 years, 8 months
Hibernate SVN: r16485 - in core/trunk/envers/src: main/java/org/hibernate/envers/reader and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-04-30 03:36:14 -0400 (Thu, 30 Apr 2009)
New Revision: 16485
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDataRevEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomNoListener.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java
core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultRevisionInfoGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java
Log:
HHH-3823:
- adding a method to obtain the current revision entity + test
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java 2009-04-30 05:53:15 UTC (rev 16484)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java 2009-04-30 07:36:14 UTC (rev 16485)
@@ -100,6 +100,20 @@
<T> T findRevision(Class<T> revisionEntityClass, Number revision) throws IllegalArgumentException,
RevisionDoesNotExistException, IllegalStateException;
+ /**
+ * Gets an instance of the current revision entity, to which any entries in the audit tables will be bound.
+ * Please note the if {@code persist} is {@code false}, and no audited entities are modified in this session,
+ * then the obtained revision entity instance won't be persisted. If {@code persist} is {@code true}, the revision
+ * entity instance will always be persisted, regardless of whether audited entities are changed or not.
+ * @param revisionEntityClass Class of the revision entity. Should be annotated with {@link RevisionEntity}.
+ * @param persist If the revision entity is not yet persisted, should it become persisted. This way, the primary
+ * identifier (id) will be filled (if it's assigned by the DB) and available, but the revision entity will be
+ * persisted even if there are no changes to audited entities. Otherwise, the revision number (id) can be
+ * {@code null}.
+ * @return The current revision entity, to which any entries in the audit tables will be bound.
+ */
+ <T> T getCurrentRevision(Class<T> revisionEntityClass, boolean persist);
+
/**
*
* @return A query creator, associated with this AuditReader instance, with which queries can be
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2009-04-30 05:53:15 UTC (rev 16484)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2009-04-30 07:36:14 UTC (rev 16485)
@@ -34,10 +34,12 @@
import org.hibernate.envers.query.AuditEntity;
import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull;
import static org.hibernate.envers.tools.ArgumentsTools.checkPositive;
+import org.hibernate.envers.synchronization.AuditSync;
import org.hibernate.NonUniqueResultException;
import org.hibernate.Query;
import org.hibernate.Session;
+import org.hibernate.event.EventSource;
import org.hibernate.engine.SessionImplementor;
import org.jboss.envers.query.VersionsQueryCreator;
@@ -190,7 +192,20 @@
}
}
- public VersionsQueryCreator createQuery() {
+ @SuppressWarnings({"unchecked"})
+ public <T> T getCurrentRevision(Class<T> revisionEntityClass, boolean persist) {
+ if (!(session instanceof EventSource)) {
+ throw new IllegalArgumentException("The provided session is not an EventSource!");
+ }
+
+ // Obtaining the current audit sync
+ AuditSync auditSync = verCfg.getSyncManager().get((EventSource) session);
+
+ // And getting the current revision data
+ return (T) auditSync.getCurrentRevisionData(session, persist);
+ }
+
+ public VersionsQueryCreator createQuery() {
return new VersionsQueryCreator(verCfg, this);
}
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultRevisionInfoGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2009-04-30 05:53:15 UTC (rev 16484)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/DefaultRevisionInfoGenerator.java 2009-04-30 07:36:14 UTC (rev 16485)
@@ -63,14 +63,18 @@
}
}
- private Object newRevision() {
- Object revisionInfo;
+ public void saveRevisionData(Session session, Object revisionData) {
+ session.save(revisionInfoEntityName, revisionData);
+ }
+
+ public Object generate() {
+ Object revisionInfo;
try {
revisionInfo = revisionInfoClass.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
-
+
revisionTimestampSetter.set(revisionInfo, System.currentTimeMillis(), null);
if (listener != null) {
@@ -79,10 +83,4 @@
return revisionInfo;
}
-
- public Object generate(Session session) {
- Object revisionData = newRevision();
- session.save(revisionInfoEntityName, revisionData);
- return revisionData;
- }
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoGenerator.java 2009-04-30 05:53:15 UTC (rev 16484)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoGenerator.java 2009-04-30 07:36:14 UTC (rev 16485)
@@ -29,5 +29,6 @@
* @author Adam Warski (adam at warski dot org)
*/
public interface RevisionInfoGenerator {
- Object generate(Session session);
+ void saveRevisionData(Session session, Object revisionData);
+ Object generate();
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java 2009-04-30 05:53:15 UTC (rev 16484)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/AuditSync.java 2009-04-30 07:36:14 UTC (rev 16485)
@@ -111,9 +111,8 @@
}
private void executeInSession(Session session) {
- if (revisionData == null) {
- revisionData = revisionInfoGenerator.generate(session);
- }
+ // Making sure the revision data is persisted.
+ getCurrentRevisionData(session, true);
AuditWorkUnit vwu;
@@ -127,6 +126,20 @@
}
}
+ public Object getCurrentRevisionData(Session session, boolean persist) {
+ // Generating the revision data if not yet generated
+ if (revisionData == null) {
+ revisionData = revisionInfoGenerator.generate();
+ }
+
+ // Saving the revision data, if not yet saved and persist is true
+ if (!session.contains(revisionData) && persist) {
+ revisionInfoGenerator.saveRevisionData(session, revisionData);
+ }
+
+ return revisionData;
+ }
+
public void beforeCompletion() {
if (workUnits.size() == 0 && undoQueue.size() == 0) {
return;
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDataRevEntity.java (from rev 16482, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomRevEntity.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDataRevEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/reventity/CustomDataRevEntity.java 2009-04-30 07:36:14 UTC (rev 16485)
@@ -0,0 +1,95 @@
+/*
+ * 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.envers.test.entities.reventity;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.envers.RevisionEntity;
+import org.hibernate.envers.RevisionNumber;
+import org.hibernate.envers.RevisionTimestamp;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@RevisionEntity
+public class CustomDataRevEntity {
+ @Id
+ @GeneratedValue
+ @RevisionNumber
+ private int customId;
+
+ @RevisionTimestamp
+ private long customTimestamp;
+
+ private String data;
+
+ public int getCustomId() {
+ return customId;
+ }
+
+ public void setCustomId(int customId) {
+ this.customId = customId;
+ }
+
+ public long getCustomTimestamp() {
+ return customTimestamp;
+ }
+
+ public void setCustomTimestamp(long customTimestamp) {
+ this.customTimestamp = customTimestamp;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof CustomDataRevEntity)) return false;
+
+ CustomDataRevEntity that = (CustomDataRevEntity) o;
+
+ if (customId != that.customId) return false;
+ if (customTimestamp != that.customTimestamp) return false;
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = customId;
+ result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32));
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+}
\ No newline at end of file
Copied: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomNoListener.java (from rev 16482, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java)
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomNoListener.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomNoListener.java 2009-04-30 07:36:14 UTC (rev 16485)
@@ -0,0 +1,137 @@
+/*
+ * 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.envers.test.integration.reventity;
+
+import java.util.Arrays;
+import java.util.Date;
+import javax.persistence.EntityManager;
+
+import org.hibernate.envers.AuditReader;
+import org.hibernate.envers.exception.RevisionDoesNotExistException;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.StrTestEntity;
+import org.hibernate.envers.test.entities.reventity.CustomDataRevEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import org.hibernate.ejb.Ejb3Configuration;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CustomNoListener extends AbstractEntityTest {
+ private Integer id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(CustomDataRevEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() throws InterruptedException {
+ EntityManager em = getEntityManager();
+
+ // Revision 1
+ em.getTransaction().begin();
+ StrTestEntity te = new StrTestEntity("x");
+ em.persist(te);
+ id = te.getId();
+
+ // Setting the data on the revision entity
+ CustomDataRevEntity custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
+ custom.setData("data1");
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+ te = em.find(StrTestEntity.class, id);
+ te.setStr("y");
+
+ // Setting the data on the revision entity
+ custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
+ custom.setData("data2");
+
+ em.getTransaction().commit();
+
+ // Revision 3 - no changes, but rev entity should be persisted
+ em.getTransaction().begin();
+
+ // Setting the data on the revision entity
+ custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, true);
+ custom.setData("data3");
+
+ em.getTransaction().commit();
+
+ // No changes, rev entity won't be persisted
+ em.getTransaction().begin();
+
+ // Setting the data on the revision entity
+ custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
+ custom.setData("data4");
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+ te = em.find(StrTestEntity.class, id);
+ te.setStr("z");
+
+ // Setting the data on the revision entity
+ custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
+ custom.setData("data5");
+
+ custom = getAuditReader().getCurrentRevision(CustomDataRevEntity.class, false);
+ custom.setData("data5bis");
+
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testFindRevision() {
+ AuditReader vr = getAuditReader();
+
+ assert "data1".equals(vr.findRevision(CustomDataRevEntity.class, 1).getData());
+ assert "data2".equals(vr.findRevision(CustomDataRevEntity.class, 2).getData());
+ assert "data3".equals(vr.findRevision(CustomDataRevEntity.class, 3).getData());
+ assert "data5bis".equals(vr.findRevision(CustomDataRevEntity.class, 4).getData());
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2, 4).equals(getAuditReader().getRevisions(StrTestEntity.class, id));
+ }
+
+ @Test
+ public void testHistoryOfId1() {
+ StrTestEntity ver1 = new StrTestEntity("x", id);
+ StrTestEntity ver2 = new StrTestEntity("y", id);
+ StrTestEntity ver3 = new StrTestEntity("z", id);
+
+ assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1);
+ assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2);
+ assert getAuditReader().find(StrTestEntity.class, id, 3).equals(ver2);
+ assert getAuditReader().find(StrTestEntity.class, id, 4).equals(ver3);
+ }
+}
\ No newline at end of file
15 years, 8 months
Hibernate SVN: r16484 - core/trunk/documentation/envers/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-04-30 01:53:15 -0400 (Thu, 30 Apr 2009)
New Revision: 16484
Modified:
core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml
core/trunk/documentation/envers/src/main/docbook/en-US/content/quickstart.xml
Log:
HHH-3879:
- updating the docs with information on default listeners that should be included so that ejb3 lifecycle callback methods work
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml 2009-04-30 05:47:36 UTC (rev 16483)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/configuration.xml 2009-04-30 05:53:15 UTC (rev 16484)
@@ -157,11 +157,11 @@
<!-- other hibernate properties -->
<property name="hibernate.ejb.event.post-insert"
- value="org.hibernate.envers.event.AuditEventListener" />
+ value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-update"
- value="org.hibernate.envers.event.AuditEventListener" />
+ value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-delete"
- value="org.hibernate.envers.event.AuditEventListener" />
+ value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-update"
value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-remove"
@@ -176,6 +176,11 @@
</persistence-unit></programlisting>
<para>
+ The <literal>EJB3Post...EvenListener</literal>s are needed, so that ejb3 entity lifecycle callback
+ methods work (<literal>@PostPersist, @PostUpdate, @PostRemove</literal>.
+ </para>
+
+ <para>
You can also set the name of the audit table on a per-entity basis, using the
<literal>@AuditTable</literal> annotation. It may be tedious to add this
annotation to every audited entity, so if possible, it's better to use a prefix/suffix.
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/quickstart.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/quickstart.xml 2009-04-30 05:47:36 UTC (rev 16483)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/quickstart.xml 2009-04-30 05:53:15 UTC (rev 16484)
@@ -42,11 +42,11 @@
<!-- other hibernate properties -->
<property name="hibernate.ejb.event.post-insert"
- value="org.hibernate.envers.event.AuditEventListener" />
+ value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-update"
- value="org.hibernate.envers.event.AuditEventListener" />
+ value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-delete"
- value="org.hibernate.envers.event.AuditEventListener" />
+ value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-update"
value="org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.pre-collection-remove"
@@ -57,6 +57,11 @@
</persistence-unit></programlisting>
<para>
+ The <literal>EJB3Post...EvenListener</literal>s are needed, so that ejb3 entity lifecycle callback
+ methods work (<literal>@PostPersist, @PostUpdate, @PostRemove</literal>.
+ </para>
+
+ <para>
Then, annotate your persistent class with <literal>@Audited</literal> - this will make all
properties audited. For example:
</para>
15 years, 8 months
Hibernate SVN: r16483 - in core/trunk/envers/src/main/java/org/hibernate/envers/configuration: metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-04-30 01:47:36 -0400 (Thu, 30 Apr 2009)
New Revision: 16483
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/MetadataTools.java
Log:
HHH-3888, ENVERS-70:
- copying the scale, precision and sql-type attributes to the column definition
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-04-29 21:18:35 UTC (rev 16482)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java 2009-04-30 05:47:36 UTC (rev 16483)
@@ -76,11 +76,11 @@
Element idProperty = MetadataTools.addNativelyGeneratedId(class_mapping, revisionInfoIdData.getName(),
revisionPropType);
- MetadataTools.addColumn(idProperty, "REV", null);
+ MetadataTools.addColumn(idProperty, "REV", null, 0, 0, null);
Element timestampProperty = MetadataTools.addProperty(class_mapping, revisionInfoTimestampData.getName(),
revisionInfoTimestampType, true, false);
- MetadataTools.addColumn(timestampProperty, "REVTSTMP", null);
+ MetadataTools.addColumn(timestampProperty, "REVTSTMP", null, 0, 0, null);
return document;
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-04-29 21:18:35 UTC (rev 16482)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-04-30 05:47:36 UTC (rev 16483)
@@ -90,7 +90,7 @@
void addRevisionInfoRelation(Element any_mapping) {
Element rev_mapping = (Element) revisionInfoRelationMapping.clone();
rev_mapping.addAttribute("name", verEntCfg.getRevisionFieldName());
- MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionFieldName(), null);
+ MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionFieldName(), null, 0, 0, null);
any_mapping.add(rev_mapping);
}
@@ -197,7 +197,7 @@
Element joinKey = joinElement.addElement("key");
MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator());
- MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null);
+ MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null, 0, 0, null);
}
}
@@ -303,7 +303,7 @@
// Adding the "key" element with all columns + the revision number column
Element keyMapping = mappingData.getFirst().addElement("key");
MetadataTools.addColumns(keyMapping, pc.getIdentifierProperty().getColumnIterator());
- MetadataTools.addColumn(keyMapping, verEntCfg.getRevisionFieldName(), null);
+ MetadataTools.addColumn(keyMapping, verEntCfg.getRevisionFieldName(), null, 0, 0, null);
break;
case TABLE_PER_CLASS:
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/MetadataTools.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/MetadataTools.java 2009-04-29 21:18:35 UTC (rev 16482)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/MetadataTools.java 2009-04-30 05:47:36 UTC (rev 16483)
@@ -68,13 +68,23 @@
return prop_mapping;
}
- public static Element addColumn(Element parent, String name, Integer length) {
+ public static Element addColumn(Element parent, String name, Integer length, Integer scale, Integer precision,
+ String sqlType) {
Element column_mapping = parent.addElement("column");
column_mapping.addAttribute("name", name);
if (length != null) {
column_mapping.addAttribute("length", length.toString());
}
+ if (scale != 0) {
+ column_mapping.addAttribute("scale", Integer.toString(scale));
+ }
+ if (precision != 0) {
+ column_mapping.addAttribute("precision", Integer.toString(precision));
+ }
+ if (sqlType != null) {
+ column_mapping.addAttribute("sql-type", sqlType);
+ }
return column_mapping;
}
@@ -142,7 +152,8 @@
public static void addColumns(Element any_mapping, Iterator<Column> columns) {
while (columns.hasNext()) {
Column column = columns.next();
- addColumn(any_mapping, column.getName(), column.getLength());
+ addColumn(any_mapping, column.getName(), column.getLength(), column.getScale(), column.getPrecision(),
+ column.getSqlType());
}
}
15 years, 8 months