[hibernate-commits] Hibernate SVN: r11088 - in branches/Branch_3_2/Hibernate3: test/org/hibernate/test/legacy and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jan 24 09:29:43 EST 2007


Author: max.andersen at jboss.com
Date: 2007-01-24 09:29:43 -0500 (Wed, 24 Jan 2007)
New Revision: 11088

Modified:
   branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultReplicateEventListener.java
   branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/ParentChildTest.java
Log:
HHH-2378 replicate() of non-versioned entiy can result in wrong value for version in entity cache

Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultReplicateEventListener.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultReplicateEventListener.java	2007-01-23 20:12:25 UTC (rev 11087)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/event/def/DefaultReplicateEventListener.java	2007-01-24 14:29:43 UTC (rev 11088)
@@ -74,11 +74,10 @@
 		}
 		else {
 			//what is the version on the database?
-			oldVersion = persister.getCurrentVersion( id, source );
+			oldVersion = persister.getCurrentVersion( id, source );			
 		}
 
-		if ( oldVersion != null ) {
-			//existing row - do an update if appropriate
+		if ( oldVersion != null ) { 			
 			if ( log.isTraceEnabled() ) {
 				log.trace(
 						"found existing row for " +
@@ -86,16 +85,19 @@
 				);
 			}
 
+			/// HHH-2378
+			final Object realOldVersion = persister.isVersioned() ? oldVersion : null;
+			
 			boolean canReplicate = replicationMode.shouldOverwriteCurrentVersion(
 					entity,
-					oldVersion,
+					realOldVersion,
 					persister.getVersion( entity, source.getEntityMode() ),
 					persister.getVersionType()
 			);
 
 			if ( canReplicate ) {
 				//will result in a SQL UPDATE:
-				performReplication( entity, id, oldVersion, persister, replicationMode, source );
+				performReplication( entity, id, realOldVersion, persister, replicationMode, source );
 			}
 			else {
 				//else do nothing (don't even reassociate object!)

Modified: branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/ParentChildTest.java
===================================================================
--- branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/ParentChildTest.java	2007-01-23 20:12:25 UTC (rev 11087)
+++ branches/Branch_3_2/Hibernate3/test/org/hibernate/test/legacy/ParentChildTest.java	2007-01-24 14:29:43 UTC (rev 11088)
@@ -27,6 +27,8 @@
 import org.hibernate.dialect.DB2Dialect;
 import org.hibernate.dialect.HSQLDialect;
 import org.hibernate.dialect.MySQLDialect;
+import org.hibernate.engine.EntityEntry;
+import org.hibernate.impl.SessionImpl;
 import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
 
 
@@ -80,6 +82,12 @@
 		s.close();
 		s = openSession();
 		s.replicate(baz, ReplicationMode.OVERWRITE);
+		
+		// HHH-2378
+		SessionImpl x = (SessionImpl)s;
+		EntityEntry entry = x.getPersistenceContext().getEntry( baz );
+		assertNull(entry.getVersion());
+		
 		s.flush();
 		s.connection().commit();
 		s.close();




More information about the hibernate-commits mailing list