EntityManager.persist() not throwing EntityExistsException for existing row in database

Description

When using the JPA 2.1 interfaces, I am not receiving an EntityExistsException when an item is persisted.

Here is my testcase code that demonstrates the behavior:

The Item.persist method is implemented as follows:

When I execute the test the first time, the database assigns an identifier of 2. When the test terminates the database still holds a row with that identifier. When I re-execute the test, the identifier is generated with the same value (it has located the row in the database) and an EntityExistsException is not thrown.

The cause of this seems to be that I have a script that preloads a root entry into another table. This entry must have identifier = 1. It must be inserted directly into the table prior to test execution because that table has a parent/child foreign key that necessitates a TOP level object that can't be set at runtime. I then update the generated hibernate_sequence nextval to 2 to avoid re-use of the 1 value.

When the identifier generator code runs, it provides the identifier of 2 to the new object. It appears when persisting this object, the code identifies the row as existing and does not attempt an insert. Hence no EntityExistsException is identified.

Activity

Show:

Scott Roehrig August 13, 2020 at 12:11 AM

So apparently I am WAY behind. Can you please close this off? I can’t seem to cancel it to get rid of it from your lists :)

Former user August 15, 2016 at 10:34 PM

Please attach a short but complete test case that
reproduces the reported bug.

Scott Roehrig July 17, 2016 at 8:35 PM

I forget to add that if I do a find(Class, 2) it will NOT find the instance.

Out of Date

Details

Assignee

Reporter

Components

Affects versions

Priority

Created July 17, 2016 at 8:20 PM
Updated April 8, 2022 at 1:33 PM
Resolved April 8, 2022 at 1:33 PM