[hibernate-commits] Hibernate SVN: r18270 - in core/branches/Branch_3_3: testsuite/src/test/java/org/hibernate/test/readonly and 1 other directory.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Dec 18 15:44:36 EST 2009
Author: gbadner
Date: 2009-12-18 15:44:35 -0500 (Fri, 18 Dec 2009)
New Revision: 18270
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/EntityEntry.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java
Log:
HHH-4715 : Unexpected results when an unpdated entity that is already modifiable is set to modifiable again
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/EntityEntry.java
===================================================================
--- core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/EntityEntry.java 2009-12-18 20:04:44 UTC (rev 18269)
+++ core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/EntityEntry.java 2009-12-18 20:44:35 UTC (rev 18270)
@@ -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/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java
===================================================================
--- core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java 2009-12-18 20:04:44 UTC (rev 18269)
+++ core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/readonly/ReadOnlyVersionedNodesTest.java 2009-12-18 20:44:35 UTC (rev 18270)
@@ -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();
More information about the hibernate-commits
mailing list