Hi,
I'm trying to, for various reasons, map an association object as a table. The table and object graph looks like this:
Code:
A -- * B ---* C
|
*
BtoD * -- D
Here's the mapping on the relationship collections (psuedo just showing the cascades 'cause I'm convinced that's what's most importent):
Every class is using uuid.hex as id generator and null as unsaved strategy.
Code:
<class name="A" table="A">
<set name="bs" inverse="true" cascade="all">
</set>
</class>
<class name="B" table="B">
<many-to-one name="A" column="A" class="A" cascade="save-update"/>
<set name="cs" cascade="all">
</set>
<set name="BtoD" cascade="all">
</set>
</class>
<class name="C" table="C">
<many-to-one name="B" column="B" class="B" cascade="save-update"/>
</class>
<class name="BtoD" table="BtoD">
<many-to-one name="B" column="B" class="B" cascade="save-update"/>
<many-to-one name="D" column="D" class="D" cascade="all"/>
</class>
<class name="D" table="D">
<set name="BtoD" cascade="all">
</set>
</class>
The topmost object in the graph is the object A. This object is loaded from DB to UI in one session.
In UI, object A gets mofified and then sent down to a business object method trying to update the changes and delete one object from the graph looking like this:
Code:
public void deletaAnObject(Object objectToDelete) {
Transaction txn = session.beginTransaction();
session.update(updateTopmostObjectA);
D theDObjectIdLikeToRemove = updateTopmostObjectA.getObjectD();
// Done to remove itself from all associations
theDObjectIdLikeToRemove.delete();
session.delete(theDObjectIdLikeToRemove);
txn.commit();
}
In my object D I invoke a method delete() just before session.delete(objectD);
That method does the following:
Code:
public void delete() {
Set myBtoDObjects = this.getBtoDObjects();
Iterator BtoDIterator = myBtoDObjects.iterator();
while (BtoDIterator.hasNext()) {
// This method is inoked on BtoD object to remove itself from any association
((BtoD) BtoDIterator.next()).delete();
}
myBtoDObjects.clear();
}
And the delete() method in BtoD object looks like this:
Code:
public void delete() {
Set BtoDFromParentObjectB = this.getParentObjectB().getMyChildsBtoD();
BtoDFromParentObjectB.remove(this);
Set BtoDFromParentObjectD = this.getParentObjectD().getMyChildsBtoD();
BtoDFromParentObjectD.remove(this);
}
I can se that the delete is performed, and when the session gets flushed I get the commonly "cascade during flush is dangerous".
I've tried to change the cascading, remove every possible (I think) associated object, using inverse on both B set and D set vice-versa and so on etc. (According to the docs and posts in this forum) without any luck.
I'm hoping that someone could give me some pointer on the problem!
Kind regards, Andreas