-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Flush during cascade dangerous, what's missing???
PostPosted: Fri Dec 05, 2003 10:03 am 
Regular
Regular

Joined: Wed Aug 27, 2003 2:55 am
Posts: 90
Location: Sweden
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 11:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Did you try http://www.hibernate.org/74.html#A8

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 11:56 am 
Regular
Regular

Joined: Wed Aug 27, 2003 2:55 am
Posts: 90
Location: Sweden
Yep!

The following have something to do with it I believe:

Before I call session.delete(myBObject), I try to delete all references to that particular object.

Code:
myBObject.getMyAObject().getBObjects().remove(myBObject);

Set myBDObjects = myBObjects.getMyBDObjects();
if (myBDObjects != null) {
    Iterator bdIterator = myBDObjects.iterator();
    while (bdIterator.hasNext()) {
        BDObject bdObject = (BDObject) bdIterator.next();
        bdObject.setBObject(null);
        myBDObject.remove(bdObject);
       
        DObject dObject = bdObject.getDObject();
        Set bdObjectFromDObject = dObject.getBDObjects();
        if (bdObjectsFromDObjects != null) {
            Iterator anotherBDIterator = bdObjectsFromDObject.iterator();
            while (anotherBDIterator.hasNext()) {
                BDObject anotherBDObject = (BDObject) anotherBDIterator.next();
                anotherBDObject.setBObject(null);
                bdObjectsFromDObjects.remove(anotherBDObject);
            }
        }
    }
}


Code above generates:

Code:
java.util.ConcurrentModificationException


Well, I'm just trying to remove all references to B...

Regards, Andreas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.