See
http://forum.hibernate.org/viewtopic.php?p=2376465 for more details.
I have amended the DeleteTest to show my problem:
Code:
public void testRefreshAfterDeleteInOtherSession() {
Session s = openSession();
s.beginTransaction();
Node parent = new Node( "parent" );
Node child = new Node( "child" );
parent.getCascadingChildren().add( child );
assertEquals("s parent has 1 child", 1, parent.getCascadingChildren().size());
s.persist( parent );
s.getTransaction().commit();
s.flush();
deleteChildViaOtherSession("parent");
s.refresh(parent);
assertEquals("s parent has no children", 0, parent.getCascadingChildren().size());
}
private Node deleteChildViaOtherSession(String parentId) {
Node parent;
Session s2 = openSession();
s2.beginTransaction();
parent = ( Node ) s2.get( Node.class, parentId);
parent.getCascadingChildren().clear();
s2.getTransaction().commit();
s2.flush();
s2.close();
return parent;
}
And the node hbm file:
Code:
<class name="Node" polymorphism="explicit">
<id name="name">
<generator class="assigned"/>
</id>
<property name="description"/>
<many-to-one name="parent"/>
<property name="created" not-null="true"/>
<set name="children"
inverse="true"
cascade="persist,merge,save-update,evict">
<key column="parent"/>
<one-to-many class="Node"/>
</set>
<set name="cascadingChildren" inverse="false" cascade="persist,merge,save-update,evict,delete,refresh,delete-orphan">
<key column="CASC_PARENT"/>
<one-to-many class="Node"/>
</set>
</class>
NOTE the delete-orphan cascade added to the cascadingChildren.
The test fails - ie refreshing the parent gives an error when a child has been deleted in a different session. Should the refresh method handle this or does it mean you need to do a full reload to get the right data?
Thanks in advance,
Chris