[hibernate-commits] Hibernate SVN: r11490 - in trunk/Hibernate3: test/org/hibernate/test and 1 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Tue May 8 21:43:11 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-05-08 21:43:11 -0400 (Tue, 08 May 2007)
New Revision: 11490
Added:
trunk/Hibernate3/test/org/hibernate/test/reattachment/
trunk/Hibernate3/test/org/hibernate/test/reattachment/Child.java
trunk/Hibernate3/test/org/hibernate/test/reattachment/CollectionReattachmentTest.java
trunk/Hibernate3/test/org/hibernate/test/reattachment/Mappings.hbm.xml
trunk/Hibernate3/test/org/hibernate/test/reattachment/Parent.java
trunk/Hibernate3/test/org/hibernate/test/reattachment/ProxyReattachmentTest.java
trunk/Hibernate3/test/org/hibernate/test/reattachment/ReattachmentSuite.java
Modified:
trunk/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java
trunk/Hibernate3/test/org/hibernate/test/AllTests.java
Log:
HHH-511 : collection reattachment
Modified: trunk/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java 2007-05-09 01:42:44 UTC (rev 11489)
+++ trunk/Hibernate3/src/org/hibernate/engine/StatefulPersistenceContext.java 2007-05-09 01:43:11 UTC (rev 11490)
@@ -178,6 +178,15 @@
}
public void clear() {
+ Iterator itr = proxiesByKey.values().iterator();
+ while ( itr.hasNext() ) {
+ final LazyInitializer li = ( ( HibernateProxy ) itr.next() ).getHibernateLazyInitializer();
+ li.setSession( null );
+ }
+ Map.Entry[] collectionEntryArray = IdentityMap.concurrentEntries( collectionEntries );
+ for ( int i = 0; i < collectionEntryArray.length; i++ ) {
+ ( ( PersistentCollection ) collectionEntryArray[i].getKey() ).unsetSession( getSession() );
+ }
arrayHolders.clear();
entitiesByKey.clear();
entitiesByUniqueKey.clear();
Modified: trunk/Hibernate3/test/org/hibernate/test/AllTests.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2007-05-09 01:42:44 UTC (rev 11489)
+++ trunk/Hibernate3/test/org/hibernate/test/AllTests.java 2007-05-09 01:43:11 UTC (rev 11490)
@@ -130,6 +130,7 @@
import org.hibernate.test.version.sybase.SybaseTimestampVersioningTest;
import org.hibernate.test.where.WhereTest;
import org.hibernate.test.insertordering.InsertOrderingTest;
+import org.hibernate.test.reattachment.ReattachmentSuite;
/**
* @author Gavin King
@@ -302,6 +303,7 @@
suite.addTest( DialectFunctionalTestsSuite.suite() );
suite.addTest( DialectUnitTestsSuite.suite() );
suite.addTest( InsertOrderingTest.suite() );
+ suite.addTest( ReattachmentSuite.suite() );
return suite;
}
Added: trunk/Hibernate3/test/org/hibernate/test/reattachment/Child.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/reattachment/Child.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/reattachment/Child.java 2007-05-09 01:43:11 UTC (rev 11490)
@@ -0,0 +1,34 @@
+package org.hibernate.test.reattachment;
+
+/**
+ * Child entity
+ *
+ * @author Steve Ebersole
+ */
+public class Child {
+ private String name;
+ private Parent parent;
+
+ public Child() {
+ }
+
+ public Child(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Parent getParent() {
+ return parent;
+ }
+
+ public void setParent(Parent parent) {
+ this.parent = parent;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/reattachment/CollectionReattachmentTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/reattachment/CollectionReattachmentTest.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/reattachment/CollectionReattachmentTest.java 2007-05-09 01:43:11 UTC (rev 11490)
@@ -0,0 +1,78 @@
+package org.hibernate.test.reattachment;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.Session;
+
+/**
+ * Test of collection reattachment semantics
+ *
+ * @author Steve Ebersole
+ */
+public class CollectionReattachmentTest extends FunctionalTestCase {
+ public CollectionReattachmentTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( CollectionReattachmentTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "reattachment/Mappings.hbm.xml" };
+ }
+
+ public void testUpdateOwnerAfterClear() {
+ Session s = openSession();
+ s.beginTransaction();
+ Parent p = new Parent( "p" );
+ p.getChildren().add( new Child( "c" ) );
+ s.save( p );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ p = ( Parent ) s.get( Parent.class, "p" );
+ // clear...
+ s.clear();
+ // now try to reattach...
+ s.update( p );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( p );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testUpdateOwnerAfterEvict() {
+ Session s = openSession();
+ s.beginTransaction();
+ Parent p = new Parent( "p" );
+ p.getChildren().add( new Child( "c" ) );
+ s.save( p );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ p = ( Parent ) s.get( Parent.class, "p" );
+ // evict...
+ s.evict( p );
+ // now try to reattach...
+ s.update( p );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( p );
+ s.getTransaction().commit();
+ s.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/reattachment/Mappings.hbm.xml
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/reattachment/Mappings.hbm.xml (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/reattachment/Mappings.hbm.xml 2007-05-09 01:43:11 UTC (rev 11490)
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+
+<hibernate-mapping package="org.hibernate.test.reattachment">
+
+ <class name="Parent">
+ <id name="name" column="NAME" type="string" />
+ <set name="children" inverse="true" cascade="all">
+ <key column="PARENT" />
+ <one-to-many class="Child" />
+ </set>
+ </class>
+
+ <class name="Child">
+ <id name="name" column="NAME" type="string"/>
+ <many-to-one name="parent" class="Parent" cascade="none" />
+ </class>
+
+</hibernate-mapping>
Added: trunk/Hibernate3/test/org/hibernate/test/reattachment/Parent.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/reattachment/Parent.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/reattachment/Parent.java 2007-05-09 01:43:11 UTC (rev 11490)
@@ -0,0 +1,37 @@
+package org.hibernate.test.reattachment;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * Parent entity
+ *
+ * @author Steve Ebersole
+ */
+public class Parent {
+ private String name;
+ private Set children = new HashSet();
+
+ public Parent() {
+ }
+
+ public Parent(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set getChildren() {
+ return children;
+ }
+
+ public void setChildren(Set children) {
+ this.children = children;
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/reattachment/ProxyReattachmentTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/reattachment/ProxyReattachmentTest.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/reattachment/ProxyReattachmentTest.java 2007-05-09 01:43:11 UTC (rev 11490)
@@ -0,0 +1,76 @@
+package org.hibernate.test.reattachment;
+
+import junit.framework.Test;
+
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.junit.functional.FunctionalTestClassTestSuite;
+import org.hibernate.Session;
+
+/**
+ * Test of proxy reattachment semantics
+ *
+ * @author Steve Ebersole
+ */
+public class ProxyReattachmentTest extends FunctionalTestCase {
+ public ProxyReattachmentTest(String string) {
+ super( string );
+ }
+
+ public static Test suite() {
+ return new FunctionalTestClassTestSuite( ProxyReattachmentTest.class );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "reattachment/Mappings.hbm.xml" };
+ }
+
+ public void testUpdateAfterEvict() {
+ Session s = openSession();
+ s.beginTransaction();
+ Parent p = new Parent( "p" );
+ s.save( p );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ p = ( Parent ) s.load( Parent.class, "p" );
+ // evict...
+ s.evict( p );
+ // now try to reattach...
+ s.update( p );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( p );
+ s.getTransaction().commit();
+ s.close();
+ }
+
+ public void testUpdateAfterClear() {
+ Session s = openSession();
+ s.beginTransaction();
+ Parent p = new Parent( "p" );
+ s.save( p );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ p = ( Parent ) s.load( Parent.class, "p" );
+ // clear...
+ s.clear();
+ // now try to reattach...
+ s.update( p );
+ s.getTransaction().commit();
+ s.close();
+
+ s = openSession();
+ s.beginTransaction();
+ s.delete( p );
+ s.getTransaction().commit();
+ s.close();
+ }
+}
Added: trunk/Hibernate3/test/org/hibernate/test/reattachment/ReattachmentSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/reattachment/ReattachmentSuite.java (rev 0)
+++ trunk/Hibernate3/test/org/hibernate/test/reattachment/ReattachmentSuite.java 2007-05-09 01:43:11 UTC (rev 11490)
@@ -0,0 +1,18 @@
+package org.hibernate.test.reattachment;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Suite of reattachment specific tests.
+ *
+ * @author Steve Ebersole
+ */
+public class ReattachmentSuite {
+ public static Test suite() {
+ TestSuite suite = new TestSuite( "reattachment semantics" );
+ suite.addTest( CollectionReattachmentTest.suite() );
+ suite.addTest( ProxyReattachmentTest.suite() );
+ return suite;
+ }
+}
More information about the hibernate-commits
mailing list