Author: gbadner
Date: 2009-12-17 22:38:16 -0500 (Thu, 17 Dec 2009)
New Revision: 18261
Modified:
core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java
core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java
Log:
HHH-4715 : Unexpected results when an entity that is already modifiable is set to
modifiable again
Modified: core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java 2009-12-17
21:14:07 UTC (rev 18260)
+++ core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java 2009-12-18
03:38:16 UTC (rev 18261)
@@ -262,6 +262,11 @@
}
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");
}
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java
===================================================================
---
core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java 2009-12-17
21:14:07 UTC (rev 18260)
+++
core/trunk/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java 2009-12-18
03:38:16 UTC (rev 18261)
@@ -127,6 +127,71 @@
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();
Show replies by date