Hibernate version:
2.1.6
Situation, two classes A and B.
A contains a B as a property.
A.getB() or similar.
PseudoCode:
A a = hibernate.get(A.class, some identifer);
B b = a.getB(); // B's are unique to A, lifecycle entirely dependent on A
// now I want to replace the b on that a object
a.setB(NULL);
a.setB(new B());
hibernate.save(a);
Now what its currently doing is inserting the new b and pointing a to it. However the old b becomes dereferenced and just floats in the database. What I WANT it to do is be deleted since its nolonger referenced by an A. Is this possible? (seems to me i need a cascade="all-delete-orphan" for many-to-one's, but that doesnt exist).
code snippet:
Code:
<many-to-one
name="data"
class="com.dailydose.content.management.model.FileData"
cascade="all"
outer-join="false"
update="true"
insert="true"
access="property"
column="FILEDATA_ID"
unique="true"
/>
Thanks!
David