Author: max.andersen(a)jboss.com
Date: 2007-01-24 09:34:22 -0500 (Wed, 24 Jan 2007)
New Revision: 11089
Modified:
trunk/Hibernate3/src/org/hibernate/event/def/DefaultReplicateEventListener.java
trunk/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: trunk/Hibernate3/src/org/hibernate/event/def/DefaultReplicateEventListener.java
===================================================================
---
trunk/Hibernate3/src/org/hibernate/event/def/DefaultReplicateEventListener.java 2007-01-24
14:29:43 UTC (rev 11088)
+++
trunk/Hibernate3/src/org/hibernate/event/def/DefaultReplicateEventListener.java 2007-01-24
14:34:22 UTC (rev 11089)
@@ -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: trunk/Hibernate3/test/org/hibernate/test/legacy/ParentChildTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/legacy/ParentChildTest.java 2007-01-24
14:29:43 UTC (rev 11088)
+++ trunk/Hibernate3/test/org/hibernate/test/legacy/ParentChildTest.java 2007-01-24
14:34:22 UTC (rev 11089)
@@ -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();