-->
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.  [ 1 post ] 
Author Message
 Post subject: delete, cascade and error on quering a collection
PostPosted: Wed Jun 30, 2004 2:49 pm 
Regular
Regular

Joined: Mon Jun 14, 2004 1:42 pm
Posts: 80
Location: Brazil
Hi.
I Have 3 objects: A,B,C
A has a set of B
C has a set of B

I put cascade="all" on A set of B, so that when I delete one A, all of the B objects will be deleted too.

all works ok. The problem begins when object C try to query his collection of B, and one of those B's was deleted.
I get an exception:

ERROR [STDERR] net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): 7, of class: com.labsystems.model.labsystem.Amostraexame
at net.sf.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:752)

my prog is:

Code:
// removes a and all b's related
session.delete(a);
...
Set colB = c.getBSet();
Query query = sess.createFilter(colB, "where dProp=?");
// D is another component unrellated to A,B,C
query.setEntity(0,D);
// this throws exception
List res = query.list();

Well , I don't understand why forceflush has been called. I'm doing a query, not a flush. And why he's trying to "ressurect" B ?
My question is, do I have to remove object B manually from all collections it's part of ? or I just can't use filter over collection If I'm not sure that no objects has been removed?
I can't understand very well the way it works. Any link to similiar problems and documentation would be good.
Also a second question, if an object has been removed , how can I know that ? session.contain(x) will return true.
I'm worried about the "coupling" of my business rules. It's hard to guess the state of the objects and collections, and ilegal operations are really hard to prevent. Sometimes is dificult to see the best practice for a solution.

Thank you.


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

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.