Hibernate version: 3 / JBoss 4.0.3 SP 1
Hello,
I've got a problem with evict together with cascading associations.
For example given the following model:
Class Person has association "memberOf" to class department.
Class Person has another association "proxies" to class Person.
Association "memberOf" is CascadeType=ALL.
Person p1 is memberOf Department d1.
Person p2 is memberOf the same Department.
p2 is proxy of p1.
The following code:
session.update(p1);
Hibernate.initialize(p1.getProxies());
session.evict(p1);
is used to initialize the proxy collection of p1, containing one element p2.
At end of transaction, there is an error because of an update to an object which is not in the first level cache. After some debugging I found the reason:
Evicting p1 also evicts d1 (because of cascade).
Evicting p1 does not evict p2 (because of no cascade). p2 is updated.
But: updating p2 also updates d1 (because of cascade).
d1 is already evicted. Error!
Is there something wrong with my model? What can I do to repair this?
Marcus.
|