HHH-2584 - PersistentMap.remove() incorrect on uninitialized, non-extra-lazy map
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18020 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
5c30fe6464
commit
1a31549ced
|
@ -199,17 +199,17 @@ public class PersistentMap extends AbstractPersistentCollection implements Map {
|
|||
public Object remove(Object key) {
|
||||
if ( isPutQueueEnabled() ) {
|
||||
Object old = readElementByIndex( key );
|
||||
queueOperation( new Remove( key, old ) );
|
||||
return old;
|
||||
}
|
||||
else {
|
||||
// TODO : safe to interpret "map.remove(key) == null" as non-dirty?
|
||||
initialize( true );
|
||||
if ( map.containsKey( key ) ) {
|
||||
dirty();
|
||||
if ( old != UNKNOWN ) {
|
||||
queueOperation( new Remove( key, old ) );
|
||||
return old;
|
||||
}
|
||||
return map.remove( key );
|
||||
}
|
||||
// TODO : safe to interpret "map.remove(key) == null" as non-dirty?
|
||||
initialize( true );
|
||||
if ( map.containsKey( key ) ) {
|
||||
dirty();
|
||||
}
|
||||
return map.remove( key );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<map name="children" inverse="true" cascade="all">
|
||||
<key column="PARENT" />
|
||||
<map-key type="string" />
|
||||
<map-key type="string" formula="NAME"/>
|
||||
<one-to-many class="Child" />
|
||||
</map>
|
||||
</class>
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.hibernate.junit.functional.FunctionalTestCase;
|
|||
import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
|
||||
|
||||
/**
|
||||
* todo: describe PersistentMapTest
|
||||
* Test various situations using a {@link PersistentMap}.
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -27,6 +27,7 @@ public class PersistentMapTest extends FunctionalTestCase {
|
|||
return new FunctionalTestClassTestSuite( PersistentMapTest.class );
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void testWriteMethodDirtying() {
|
||||
Parent parent = new Parent( "p1" );
|
||||
Child child = new Child( "c1" );
|
||||
|
@ -38,7 +39,7 @@ public class PersistentMapTest extends FunctionalTestCase {
|
|||
session.beginTransaction();
|
||||
session.save( parent );
|
||||
session.flush();
|
||||
// at this point, the set on parent has now been replaced with a PersistentSet...
|
||||
// at this point, the map on parent has now been replaced with a PersistentMap...
|
||||
PersistentMap children = ( PersistentMap ) parent.getChildren();
|
||||
|
||||
Object old = children.put( child.getName(), child );
|
||||
|
@ -99,4 +100,38 @@ public class PersistentMapTest extends FunctionalTestCase {
|
|||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
public void testRemoveAgainstUninitializedMap() {
|
||||
Parent parent = new Parent( "p1" );
|
||||
Child child = new Child( "c1" );
|
||||
parent.addChild( child );
|
||||
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
session.save( parent );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
// Now reload the parent and test removing the child
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
parent = ( Parent ) session.get( Parent.class, parent.getName() );
|
||||
Child child2 = ( Child ) parent.getChildren().remove( child.getName() );
|
||||
child2.setParent( null );
|
||||
assertNotNull( child2 );
|
||||
assertTrue( parent.getChildren().isEmpty() );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
// Load the parent once again and make sure child is still gone
|
||||
// then cleanup
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
parent = ( Parent ) session.get( Parent.class, parent.getName() );
|
||||
assertTrue( parent.getChildren().isEmpty() );
|
||||
session.delete( child2 );
|
||||
session.delete( parent );
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue