-->
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: bidirectional cached association problem
PostPosted: Sat May 12, 2007 4:51 pm 
Regular
Regular

Joined: Fri Dec 17, 2004 10:38 am
Posts: 54
Hello!

There is a weird behaviour in manipulating bidirectional association having inverse accociation end marked as cached (one-to-many, many-to-many, does not matter).
For example, two classes

Code:
class A {
  List<B> bs;
}

class B {
  List<A> as;
}


one end of this association have to be mapped inverse, since both can update link table, let A.bs be the inverse one.
We update B.as, remove some elements, add some elements. Persist change. If B.as accociation end is marked as cached <cache usage="rw"/>, hibernate invalidate cache region, next time B.as accessed fresh collection copy is retrived from db.
But if A.bs is marked as cached no cache region changes happend upon B.as persistence. This leads to stale collection A.bs, containing old set of B elements (removed elements present, new elements - not).
If any element B from old collection is removed (actually A element removed from B.as collection), upon initialization of A.bs exception thrown.

Temporary solution is to invalidate cache regions for A.bs collection manually, e.g. sessionFactory.evictCollection("A.bs", id), there id - is modified A element id from B.as collection.

Two questions:
Is this an optimal solution?
Why hibernate does not do this automatically, after all it knows - someone (namely not inverse association end) is responsible for collection modifications?

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.