views:

45

answers:

1

Hey guys, I just noticed that a part of code I worked on saves the same entity twice. I tried several tricks, like flush() and Transaction REQUIRES_NEW but nothing does it. But I can see while debugging that after calling persist(entity), I get an ID (IDENTITY) for that entity... but just a bit later in the code if I look at the variables I'll see the same entity with a different ID and two itenties with those IDs in the Table.

This is using Java EE 6 with Glassfish 3.0.1

A: 

What JPA provider are you using? and what version?

Enable logging (on finest) and include the log of what occurs.

If using EclipseLink to enable logging see,

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging

What value is assigned to your object's id, check to ensure it is > 0. Also ensure that you table in the database was generated with an IDENTITY column. What database are you using?

Try using TABLE sequencing to see if it has to do with IDENTITY sequencing.

Also include the source code for you class.

James