HHH-4715 : Unexpected results when an entity that is already modifiable is set to modifiable again

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18261 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Gail Badner 2009-12-18 03:38:16 +00:00
parent 4a9d8dcf0b
commit cab9873205
2 changed files with 70 additions and 0 deletions

View File

@ -262,6 +262,11 @@ public final class EntityEntry implements Serializable {
}
public void setReadOnly(boolean readOnly, Object entity) {
if ( ( readOnly && status == Status.READ_ONLY ) ||
( ( ! readOnly ) && status == Status.MANAGED ) ) {
// simply return since the status is not being changed
return;
}
if (status!=Status.MANAGED && status!=Status.READ_ONLY) {
throw new HibernateException("instance was not in a valid state");
}

View File

@ -127,6 +127,71 @@ public class ReadOnlyVersionedNodesTest extends FunctionalTestCase {
s.close();
}
public void testSetUpdateReadOnlyTwice() throws Exception {
Session s = openSession();
s.beginTransaction();
VersionedNode node = new VersionedNode( "node", "node" );
s.persist( node );
s.getTransaction().commit();
s.close();
clearCounts();
s = openSession();
s.beginTransaction();
node = ( VersionedNode ) s.get( VersionedNode.class, node.getId() );
node.setName( "node-name" );
s.setReadOnly( node, true );
s.setReadOnly( node, true );
s.getTransaction().commit();
s.close();
assertUpdateCount( 0 );
assertInsertCount( 0 );
s = openSession();
s.beginTransaction();
node = ( VersionedNode ) s.get( VersionedNode.class, node.getId() );
assertEquals( "node", node.getName() );
assertEquals( 0, node.getVersion() );
s.delete( node );
s.getTransaction().commit();
s.close();
}
public void testUpdateSetModifiable() throws Exception {
Session s = openSession();
s.beginTransaction();
VersionedNode node = new VersionedNode( "node", "node" );
s.persist( node );
s.getTransaction().commit();
s.close();
clearCounts();
s = openSession();
s.beginTransaction();
node = ( VersionedNode ) s.get( VersionedNode.class, node.getId() );
node.setName( "node-name" );
s.setReadOnly( node, false );
s.getTransaction().commit();
s.close();
assertUpdateCount( 1 );
assertInsertCount( 0 );
s = openSession();
s.beginTransaction();
node = ( VersionedNode ) s.get( VersionedNode.class, node.getId() );
assertEquals( "node-name", node.getName() );
assertEquals( 1, node.getVersion() );
s.delete( node );
s.getTransaction().commit();
s.close();
}
public void testAddNewChildToReadOnlyParent() throws Exception {
Session s = openSession();
s.beginTransaction();