openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marc Siegel" <marc.siegel...@gmail.com>
Subject Re: Why do I sometimes need to call em.find instead of em.merge
Date Wed, 28 Nov 2007 22:02:36 GMT
Yes, the usage is the common usage pattern,
    entity = em.merge(entity)

I've seen this behavior a number of times now. Does this have
something to do with a "Detached State" setting and OpenJPA
enhancement, which I saw something about in an earlier discussion on
this list but did not understand?

-Marc

On Nov 28, 2007 4:12 PM, Oliver Zeigermann <oliver@zeigermann.de> wrote:
> Are you very sure that after a merge you work on the copy returned by merge?
>
> Oliver
>
>
> 2007/11/28, Marc Siegel <marc.siegel.17@gmail.com>:
> > Detached, let's say from a em.find() call in an earlier transaction.
> >
> > -Marc
> >
> > On Nov 28, 2007 7:38 AM, Oliver Zeigermann <oliver@zeigermann.de> wrote:
> > > Where does the old enity come from?
> > >
> > > 2007/11/28, Marc Siegel <marc.siegel.17@gmail.com>:
> > >
> > > > Hi folks,
> > > >
> > > > I've had to replace a number of lines of this sort:
> > > >
> > > > em.getTransaction().begin();
> > > > entity = em.merge(entity);    // <==
> > > > entity.setSomething(value)
> > > > em.getTransaction().commit();
> > > >
> > > > With lines of this sort:
> > > >
> > > > ...
> > > > entity = em.find(entity.getClass(), entity.getId());  // <==
> > > > ...
> > > >
> > > >
> > > > Otherwise, the set field does not get written out, although all
> > > > requests to the current EntityManager will return the new values. But
> > > > if you call em.close(), and create a new EntityManager, the requests
> > > > will still show the old value.
> > > >
> > > > Can someone with insight into the code please explain?
> > > >
> > > > Thanks
> > > > -Marc
> > > >
> > >
> >
>

Mime
View raw message