On Fri, Nov 13, 2009 at 12:50 PM, Daryl Stultz <[email protected]> wrote:
> On Fri, Nov 13, 2009 at 1:09 PM, Michael Dick <[email protected] > >wrote: > > > The real issue is setting the backrefs. In JPA the application must > > maintain > > both sides of a bi-directional relationship (on your Java objects). > There's > > some wording in the spec to this effect which I can drag up if you're > > interested. > > > > I read parts of the manual regarding management of bidirectional > relationships and it struck some fear in my heart when considering enabling > L2 caching. I am currently not using L2 caching but expect to some day. It > sound as though things can get stale in the cache. If you have a parent > entity in the cache with all its children fetched and you take a child and > change its parent, later access to the parent will still have the child > related. Could that happen? This doesn't happen without L2 cache, of > course, > but the docs suggest enabling L2 cache won't change the behavior. > > If I understand the problem correctly the issue exists whether you have a L2 cache or not.. Consider the Father -> Child One -> Many relationship. If you do something like this : Child c = em.find(Child.class, 123); Father oldFather = c.getFather(); c.setFather(new Father()); oldFather.getChildren().contains(c); // will return true The caches (L1 or L2) won't be updated until you flush to the database, even with InverseManager set. Is this the scenario you mentioned? -mike > -- > Daryl Stultz > _____________________________________ > 6 Degrees Software and Consulting, Inc. > http://www.6degrees.com > mailto:[email protected] >
