openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Malte <malte.neum...@googlemail.com>
Subject Re: Problem with EntityExistsException
Date Tue, 25 Apr 2017 07:29:24 GMT
Hi!

As I wrote, this example is an excerpt from a bigger part. So it is not
just a single move from try to finally, I have to rewrite some more code.

Is there any workaround possbile to remove the entity information manually?

Best regards,
Malte

2017-04-24 21:13 GMT+02:00 Mark Struberg <struberg@yahoo.de.invalid>:

> Hi Malte!
>
> puh, that's a pretty tricky puzzler.
>
> You flush and detach. At this point the 'data' instance has the
> information that it got inserted.
> Since the entity got detached it also has no further information that the
> transaction got rolled back.
> So technically I can understand what happens.
>
> I also do not think this is ruled out by the spec. Otoh it's surely also
> not defined that it should work.
> So my guess is that you are hitting a rather unspecified area of JPA.
>
> What if you just move the detach to a finally block?
> Would that probably solve your problem?
>
> LieGrue,
> strub
>
> > Am 24.04.2017 um 17:55 schrieb Malte <malte.neumann@googlemail.com>:
> >
> > Hello all!
> >
> > In a special situation, I'll get a wrong EntityExistsException.
> >
> > I've extract the problem to a simple project (attached).
> >
> > I do this:
> >    try {
> >      entManager.persist(data);
> >      entManager.flush();
> >      entManager.detach(data);
> >
> >      doOtherDBCallsWithError();
> >
> >      entManager.getTransaction().commit();
> >    } catch (Exception e) {
> >       entManager.getTransaction().rollback();
> >
> >       entManager.getTransaction().begin();
> >       entManager.persist(data);
> >       entManager.getTransaction().commit();
> >    }
> >
> > If doOtherDBCallsWithError throws an Exception, it is not possible to
> persist the object in the catch-block. The second persists throws
> "org.apache.openjpa.persistence.EntityExistsException: Attempt to persist
> detached object "de.test.model.Test-1".  If this is a new instance, make
> sure any version and/or auto-generated primary key fields are null/default
> when persisting." If I use merge instead, the object will also not persist.
> If I remove the detach, everything works.
> >
> > Is this a bug or is the call order persist-flush-detach-commit against
> the specification?
> >
> > Best regards,
> > Malte
> > <test.zip>
>
>

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