Author: gbadner
Date: 2008-10-29 17:21:07 -0400 (Wed, 29 Oct 2008)
New Revision: 15444
Added:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/Cascade.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml
Log:
HHH-2146 : NullpointerException in DefaultDeleteEventListener.deleteTransientEntity
Modified: core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/Cascade.java
===================================================================
---
core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/Cascade.java 2008-10-29
20:40:17 UTC (rev 15443)
+++
core/branches/Branch_3_3/core/src/main/java/org/hibernate/engine/Cascade.java 2008-10-29
21:21:07 UTC (rev 15444)
@@ -25,6 +25,7 @@
package org.hibernate.engine;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import org.slf4j.Logger;
@@ -375,7 +376,7 @@
if ( log.isTraceEnabled() ) {
log.trace("deleting orphaned entity instance: " + entityName);
}
- eventSource.delete( entityName, orphan, false, null );
+ eventSource.delete( entityName, orphan, false, new HashSet() );
}
}
}
Modified:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java
===================================================================
---
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java 2008-10-29
20:40:17 UTC (rev 15443)
+++
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Address.java 2008-10-29
21:21:07 UTC (rev 15444)
@@ -1,5 +1,8 @@
package org.hibernate.test.deletetransient;
+import java.util.Set;
+import java.util.HashSet;
+
/**
* todo: describe Address
*
@@ -8,6 +11,7 @@
public class Address {
private Long id;
private String info;
+ private Set suites = new HashSet();
public Address() {
}
@@ -31,4 +35,12 @@
public void setInfo(String info) {
this.info = info;
}
+
+ public Set getSuites() {
+ return suites;
+ }
+
+ public void setSuites(Set suites) {
+ this.suites = suites;
+ }
}
Modified:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java
===================================================================
---
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2008-10-29
20:40:17 UTC (rev 15443)
+++
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/DeleteTransientEntityTest.java 2008-10-29
21:21:07 UTC (rev 15444)
@@ -105,4 +105,70 @@
t.commit();
s.close();
}
+
+ public void testCascadeAllFromClearedPersistentAssnToTransientEntity() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Person p = new Person();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ p.getAddresses().add( address );
+ s.save( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Suite suite = new Suite();
+ address.getSuites().add( suite );
+ p.getAddresses().clear();
+ s.saveOrUpdate( p );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ p = ( Person ) s.get( p.getClass(), p.getId() );
+ assertEquals( "persistent collection not cleared", 0, p.getAddresses().size()
);
+ Long count = ( Long ) s.createQuery( "select count(*) from Address"
).list().get( 0 );
+ assertEquals( 1, count.longValue() );
+ count = ( Long ) s.createQuery( "select count(*) from Suite" ).list().get( 0
);
+ assertEquals( 0, count.longValue() );
+ s.delete( p );
+ t.commit();
+ s.close();
+ }
+
+ public void testCascadeAllDeleteOrphanFromClearedPersistentAssnToTransientEntity() {
+ Session s = openSession();
+ Transaction t = s.beginTransaction();
+ Address address = new Address();
+ address.setInfo( "123 Main St." );
+ Suite suite = new Suite();
+ address.getSuites().add( suite );
+ s.save( address );
+ t.commit();
+ s.close();
+
+
+ s = openSession();
+ t = s.beginTransaction();
+ Note note = new Note();
+ note.setDescription( "a description" );
+ suite.getNotes().add( note );
+ address.getSuites().clear();
+ s.saveOrUpdate( address );
+ t.commit();
+ s.close();
+
+ s = openSession();
+ t = s.beginTransaction();
+ Long count = ( Long ) s.createQuery( "select count(*) from Suite"
).list().get( 0 );
+ assertEquals( "all-delete-orphan not cascaded properly to cleared persistent
collection entities", 0, count.longValue() );
+ count = ( Long ) s.createQuery( "select count(*) from Note" ).list().get( 0
);
+ assertEquals( 0, count.longValue() );
+ s.delete( address );
+ t.commit();
+ s.close();
+ }
}
Added:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java
===================================================================
---
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java
(rev 0)
+++
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Note.java 2008-10-29
21:21:07 UTC (rev 15444)
@@ -0,0 +1,33 @@
+package org.hibernate.test.deletetransient;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class Note {
+ private Long id;
+ private String description;
+
+ public Note() {
+ }
+
+ public Note(String description) {
+ this.description = description;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+}
\ No newline at end of file
Modified:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml
===================================================================
---
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml 2008-10-29
20:40:17 UTC (rev 15443)
+++
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Person.hbm.xml 2008-10-29
21:21:07 UTC (rev 15444)
@@ -29,6 +29,28 @@
<generator class="increment"/>
</id>
<property name="info" type="string"/>
+ <set name="suites" lazy="true" inverse="false"
cascade="all-delete-orphan">
+ <key column="ADDRESS_ID"/>
+ <one-to-many class="Suite"/>
+ </set>
</class>
-
+
+ <class name="Suite" table="T_SUITE">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="location" type="string"/>
+ <set name="notes" lazy="true" inverse="false"
cascade="all-delete-orphan">
+ <key column="SUITE_ID"/>
+ <one-to-many class="Note"/>
+ </set>
+ </class>
+
+ <class name="Note" table="T_NOTE">
+ <id name="id" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="description" type="string"/>
+ </class>
+
</hibernate-mapping>
Added:
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java
===================================================================
---
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java
(rev 0)
+++
core/branches/Branch_3_3/testsuite/src/test/java/org/hibernate/test/deletetransient/Suite.java 2008-10-29
21:21:07 UTC (rev 15444)
@@ -0,0 +1,47 @@
+package org.hibernate.test.deletetransient;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Gail Badner
+ */
+public class Suite {
+ private Long id;
+ private String location;
+ private Set notes = new HashSet();
+
+ public Suite() {
+ }
+
+ public Suite(String location) {
+ this.location = location;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public Set getNotes() {
+ return notes;
+ }
+
+ public void setNotes(Set notes) {
+ this.notes = notes;
+ }
+}
\ No newline at end of file