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:
parent
4a9d8dcf0b
commit
cab9873205
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue