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.