[hibernate-commits] Hibernate SVN: r11255 - in trunk/Hibernate3: test/org/hibernate/test/collection/map and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Mar 7 14:30:27 EST 2007


Author: steve.ebersole at jboss.com
Date: 2007-03-07 14:30:27 -0500 (Wed, 07 Mar 2007)
New Revision: 11255

Modified:
   trunk/Hibernate3/src/org/hibernate/collection/PersistentMap.java
   trunk/Hibernate3/test/org/hibernate/test/collection/map/Parent.java
   trunk/Hibernate3/test/org/hibernate/test/collection/map/PersistentMapTest.java
Log:
HHH-2476 : PersistentMap#put

Modified: trunk/Hibernate3/src/org/hibernate/collection/PersistentMap.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/collection/PersistentMap.java	2007-03-07 16:50:06 UTC (rev 11254)
+++ trunk/Hibernate3/src/org/hibernate/collection/PersistentMap.java	2007-03-07 19:30:27 UTC (rev 11255)
@@ -153,21 +153,21 @@
 	public Object put(Object key, Object value) {
 		if ( isPutQueueEnabled() ) {
 			Object old = readElementByIndex( key );
-			queueOperation( new Put( key, value, old ) );
-			return old;
-		}
-		else {
-			initialize( true );
-			Object old = map.put( key, value );
-			// would be better to use the element-type to determine
-			// whether the old and the new are equal here; the problem being
-			// we do not necessarily have access to the element type in all
-			// cases
-			if ( value != old ) {
-				dirty();
+			if ( old != UNKNOWN ) {
+				queueOperation( new Put( key, value, old ) );
+				return old;
 			}
-			return old;
 		}
+		initialize( true );
+		Object old = map.put( key, value );
+		// would be better to use the element-type to determine
+		// whether the old and the new are equal here; the problem being
+		// we do not necessarily have access to the element type in all
+		// cases
+		if ( value != old ) {
+			dirty();
+		}
+		return old;
 	}
 
 	/**

Modified: trunk/Hibernate3/test/org/hibernate/test/collection/map/Parent.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/map/Parent.java	2007-03-07 16:50:06 UTC (rev 11254)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/map/Parent.java	2007-03-07 19:30:27 UTC (rev 11255)
@@ -34,4 +34,15 @@
 	public void setChildren(Map children) {
 		this.children = children;
 	}
+
+	public Child addChild(String name) {
+		Child child = new Child( name );
+		addChild( child );
+		return child;
+	}
+
+	public void addChild(Child child) {
+		child.setParent( this );
+		getChildren().put( child.getName(), child );
+	}
 }

Modified: trunk/Hibernate3/test/org/hibernate/test/collection/map/PersistentMapTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/collection/map/PersistentMapTest.java	2007-03-07 16:50:06 UTC (rev 11254)
+++ trunk/Hibernate3/test/org/hibernate/test/collection/map/PersistentMapTest.java	2007-03-07 19:30:27 UTC (rev 11255)
@@ -72,4 +72,31 @@
 		session.getTransaction().commit();
 		session.close();
 	}
+
+	public void testPutAgainstUninitializedMap() {
+		// prepare map owner...
+		Session session = openSession();
+		session.beginTransaction();
+		Parent parent = new Parent( "p1" );
+		session.save( parent );
+		session.getTransaction().commit();
+		session.close();
+
+		// Now, reload the parent and test adding children
+		session = openSession();
+		session.beginTransaction();
+		parent = ( Parent ) session.get( Parent.class, parent.getName() );
+		parent.addChild( "c1" );
+		parent.addChild( "c2" );
+		session.getTransaction().commit();
+		session.close();
+
+		assertEquals( 2, parent.getChildren().size() );
+
+		session = openSession();
+		session.beginTransaction();
+		session.delete( parent );
+		session.getTransaction().commit();
+		session.close();
+	}
 }




More information about the hibernate-commits mailing list