openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: inverse OneToMany relation - getting weird
Date Mon, 16 Nov 2009 16:19:19 GMT
I see what you mean now, thanks for the explanation.

It's an interesting gotcha since it 'works' if you don't have an L2 cache
enabled or if you bypass the L2 cache. Setting InverseManager = true will
prevent the problem (or at least it did in some unit tests I wrote).

You could also put some logic into your set method to handle some of it for
you (assuming you're using field access). Something like this might work :
    public void setFather(Father father) {
        if(this.father != null) {
            if(this.father.getChildren() != null) {
                this.father.getChildren().remove(this);
            }
        }
        this.father = father;
    }

-mike

On Sat, Nov 14, 2009 at 8:56 PM, Daryl Stultz <daryl@6degrees.com> wrote:

> On Sat, Nov 14, 2009 at 4:16 PM, Michael Dick <michael.d.dick@gmail.com
> >wrote:
>
> > 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?
> >
> > I was thinking about two transactions "some time apart" meaning different
> entity managers. I definitely get that in a single transaction relations
> are
> as above. I'm thinking you are editing the father in a web interface and
> you
> remove the child. Later you edit the child and it still thinks it has that
> father.
>
> --
> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:daryl@6degrees.com
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message