[hibernate-commits] Hibernate SVN: r14911 - in core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938: src/org/hibernate/cfg and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jul 9 18:04:58 EDT 2008


Author: cbredesen
Date: 2008-07-09 18:04:57 -0400 (Wed, 09 Jul 2008)
New Revision: 14911

Modified:
   core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/build.xml
   core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/src/org/hibernate/cfg/Environment.java
   core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/src/org/hibernate/type/CollectionType.java
   core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/test/org/hibernate/test/ops/MergeTest.java
Log:
JBPAPP-938 ported changes, incremented version

Modified: core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/build.xml
===================================================================
--- core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/build.xml	2008-07-09 21:25:39 UTC (rev 14910)
+++ core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/build.xml	2008-07-09 22:04:57 UTC (rev 14911)
@@ -23,7 +23,7 @@
 	<property name="version.major" value="3"/>
 	<property name="version.minor" value="2"/>
 	<property name="version.micro" value="4"/>
-    <property name="version.qualifier" value="sp1"/>
+    <property name="version.qualifier" value="sp1.JBPAPP-938"/>
     <property name="version.full" value="${version.major}.${version.minor}.${version.micro}.${version.qualifier}"/>
     <property name="version.major_minor" value="${version.major}.${version.minor}"/>
     <property name="fullname" value="${name}-${version.full}"/>

Modified: core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/src/org/hibernate/cfg/Environment.java
===================================================================
--- core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/src/org/hibernate/cfg/Environment.java	2008-07-09 21:25:39 UTC (rev 14910)
+++ core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/src/org/hibernate/cfg/Environment.java	2008-07-09 22:04:57 UTC (rev 14911)
@@ -153,7 +153,7 @@
  */
 public final class Environment {
 
-	public static final String VERSION = "3.2.4.sp1";
+	public static final String VERSION = "3.2.4.sp1.JBPAPP-938";
 
 	/**
 	 * <tt>ConnectionProvider</tt> implementor to use when obtaining connections

Modified: core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/src/org/hibernate/type/CollectionType.java
===================================================================
--- core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/src/org/hibernate/type/CollectionType.java	2008-07-09 21:25:39 UTC (rev 14910)
+++ core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/src/org/hibernate/type/CollectionType.java	2008-07-09 22:04:57 UTC (rev 14911)
@@ -517,11 +517,15 @@
 		//the array length might not match
 		result = replaceElements( original, result, owner, copyCache, session );
 		
-		if (original==target) {
-			//get the elements back into the target
+		if ( original == target ) {
+			// get the elements back into the target making sure to handle dirty flag
+			boolean wasClean = PersistentCollection.class.isInstance( target ) && !( ( PersistentCollection ) target ).isDirty();
 			//TODO: this is a little inefficient, don't need to do a whole
 			//      deep replaceElements() call
 			replaceElements( result, target, owner, copyCache, session );
+			if ( wasClean ) {
+				( ( PersistentCollection ) target ).clearDirty();
+			}
 			result = target;
 		}
 				

Modified: core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/test/org/hibernate/test/ops/MergeTest.java	2008-07-09 21:25:39 UTC (rev 14910)
+++ core/patches/Branch_3_2_4_SP1_CP02_JBPAPP-938/test/org/hibernate/test/ops/MergeTest.java	2008-07-09 22:04:57 UTC (rev 14911)
@@ -248,6 +248,55 @@
 		cleanup();
     }
 
+	public void testNoExtraUpdatesOnPersistentMergeVersionedWithCollection() throws Exception {
+		Session s = openSession();
+		s.beginTransaction();
+		VersionedEntity parent = new VersionedEntity( "parent", "parent" );
+		VersionedEntity child = new VersionedEntity( "child", "child" );
+		parent.getChildren().add( child );
+		child.setParent( parent );
+		s.persist( parent );
+		s.getTransaction().commit();
+		s.close();
+
+		clearCounts();
+
+		// parent is now detached, but we have made no changes. so attempt to merge it
+		// into this new session; this should cause no updates...
+		s = openSession();
+		s.beginTransaction();
+		// load parent so that merge will follow entityIsPersistent path
+		VersionedEntity persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
+		// load children
+		VersionedEntity persistentChild = ( VersionedEntity ) persistentParent.getChildren().iterator().next();
+		VersionedEntity mergedParent = ( VersionedEntity ) s.merge( persistentParent ); // <-- This merge leads to failure
+		s.getTransaction().commit();
+		s.close();
+
+		assertUpdateCount( 0 );
+		assertInsertCount( 0 );
+		assertEquals( "unexpected parent version increment", parent.getVersion(), mergedParent.getVersion() );
+		VersionedEntity mergedChild = ( VersionedEntity ) mergedParent.getChildren().iterator().next();
+		assertEquals( "unexpected child version increment", child.getVersion(), mergedChild.getVersion() );
+
+		///////////////////////////////////////////////////////////////////////
+		// as a control measure, now update the node once it is loaded and
+		// make sure we get an update as a result...
+		s = openSession();
+		s.beginTransaction();
+		persistentParent = ( VersionedEntity ) s.get( VersionedEntity.class, parent.getId() );
+		persistentParent.setName( "new name" );
+		persistentParent.getChildren().add( new VersionedEntity( "child2", "new child" ) );
+		persistentParent = ( VersionedEntity ) s.merge( persistentParent );
+		s.getTransaction().commit();
+		s.close();
+		assertUpdateCount( 1 );
+		assertInsertCount( 1 );
+		///////////////////////////////////////////////////////////////////////
+
+		// cleanup();
+	}
+
 	public void testPersistThenMergeInSameTxnWithVersion() {
 		Session s = openSession();
 		Transaction tx = s.beginTransaction();




More information about the hibernate-commits mailing list