Author: gbadner
Date: 2008-04-29 19:46:43 -0400 (Tue, 29 Apr 2008)
New Revision: 14611
Modified:
core/branches/Branch_3_2/test/org/hibernate/test/ops/MergeTest.java
Log:
added tests for merging initialized and uninitialized managed collections
Modified: core/branches/Branch_3_2/test/org/hibernate/test/ops/MergeTest.java
===================================================================
--- core/branches/Branch_3_2/test/org/hibernate/test/ops/MergeTest.java 2008-04-29
23:02:13 UTC (rev 14610)
+++ core/branches/Branch_3_2/test/org/hibernate/test/ops/MergeTest.java 2008-04-29
23:46:43 UTC (rev 14611)
@@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import junit.framework.Test;
@@ -561,6 +562,94 @@
// cleanup();
}
+ public void testMergeManagedUninitializedCollection() {
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ NumberedNode root = new NumberedNode( "root" );
+ root.addChild( new NumberedNode( "child" ) );
+ s.persist(root);
+ tx.commit();
+ s.close();
+
+ clearCounts();
+
+ NumberedNode newRoot = new NumberedNode( "root" );
+ newRoot.setId( root.getId() );
+
+ s = openSession();
+ tx = s.beginTransaction();
+ root = ( NumberedNode ) s.get( NumberedNode.class, new Long( root.getId() ) );
+ Set managedChildren = root.getChildren();
+ assertFalse( Hibernate.isInitialized( managedChildren ) );
+ newRoot.setChildren( managedChildren );
+ assertSame( root, s.merge( newRoot ) );
+ assertSame( managedChildren, root.getChildren() );
+ assertFalse( Hibernate.isInitialized( managedChildren ) );
+ tx.commit();
+
+ assertInsertCount(0);
+ assertUpdateCount(0);
+ assertDeleteCount(0);
+
+ tx = s.beginTransaction();
+ assertEquals(
+ s.createCriteria(NumberedNode.class)
+ .setProjection( Projections.rowCount() )
+ .uniqueResult(),
+ new Integer(2)
+ );
+ tx.commit();
+
+ s.close();
+
+// cleanup();
+ }
+
+ public void testMergeManagedInitializedCollection() {
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ NumberedNode root = new NumberedNode( "root" );
+ root.addChild( new NumberedNode( "child" ) );
+ s.persist(root);
+ tx.commit();
+ s.close();
+
+ clearCounts();
+
+ NumberedNode newRoot = new NumberedNode( "root" );
+ newRoot.setId( root.getId() );
+
+ s = openSession();
+ tx = s.beginTransaction();
+ root = ( NumberedNode ) s.get( NumberedNode.class, new Long( root.getId() ) );
+ Set managedChildren = root.getChildren();
+ Hibernate.initialize( managedChildren );
+ assertTrue( Hibernate.isInitialized( managedChildren ) );
+ newRoot.setChildren( managedChildren );
+ assertSame( root, s.merge( newRoot ) );
+ assertSame( managedChildren, root.getChildren() );
+ assertTrue( Hibernate.isInitialized( managedChildren ) );
+ tx.commit();
+
+ assertInsertCount(0);
+ assertUpdateCount(0);
+ assertDeleteCount(0);
+
+ tx = s.beginTransaction();
+ assertEquals(
+ s.createCriteria(NumberedNode.class)
+ .setProjection( Projections.rowCount() )
+ .uniqueResult(),
+ new Integer(2)
+ );
+ tx.commit();
+
+ s.close();
+
+// cleanup();
+ }
public void testRecursiveMergeTransient() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Show replies by date