Hi,
I've read several posts on this forum saying that all references to the deleted object should be removed on ANY associations.
Example:
Code:
Customer one-to-many Order
inverse=true is set on the 'Customer' side, cascade=all.
The we should do the following:
Code:
order.getCustomer().getOrders().remove(order);
session.delete(order);
, inside an transaction.
I've got a pretty complex domain to map, well here it goes...
Consider the following object graph:
Code:
A --* B *-- C
|
*
BD *-- D
|
*
BDE *-- E
I'm trying to delete an object B1 from the following object graph:
Code:
A1 contains B1
A1 contains B2
B1 contains BD1
B1 contains BD2
B2 contains BD3
B2 contains BD4
BD1 contains D1 and BDE1
BD2 contains D2 and BDE2
BD3 contains D1 and BDE3
BD4 contains D2 and BDE4
BDE1 contains E1
BDE2 contains E2
BDE3 contains E1
BDE4 contains E2
In my business method performing the delete I invoke an session.update() on the parent object of the object to delete, and then I delete the object to delete reference from parent and at last call session.delete() on the object to delete.
All of this is done in one transaction.
From log I can se:
Code:
Cascades:336 - processing cascades for: BD
Cascades:87 - cascading to saveOrUpdate()
SessionImpl:1186 - saveOrUpdate() deleted instance
HibernateTransactionManager:311 - Rolling back Hibernate transaction
So, I tried to list all BD's and setting the reference to B to null, doesn't work.
Cascades is specified like this:
Code:
A --> B cascade=all
B --> A cascade=save-update
B --> C cascade=all
C --> B cascade=save-update
B --> BD cascade=all
BD --> B cascade=save-update
BD --> D cascade=all
D --> BD cascade=all
BD --> BDE cascade=all
BDE --> BD cascade=save-update
BDE --> E cascade=all
E --> BDE cascade=all
Should I manage other references manually as well, if so which?
Kind regards, Andreas