Reputation: 678
I'm getting this PersistanceObjectException being thrown during one of my integration tests.
The the test it self runs fine when run on its own, but not as part as a test suite. So I added DirtiesContext to all the integration tests, however this for some reason has had no affect.
I've confirmed that the entity I'm trying to persist DOES NOT exist, when I try to persist it. However, the error only occurs when a previous test (in a different class) does the same persist.
If this was a case of the entity staying persisted from one case to the next, why isn't DirtiesContext would fix this, and my check to see if the entity is already persisted would be true.
The persist operation is a simple entityManager.persist(entity). Nothing complex or fancy.
Any ideas? I'm really stumped on this one.
Upvotes: 1
Views: 50
Reputation: 153780
It depends on how you set up the integration testing database. The DirtyContext setting will only recreate the Spring application context, so unless you have a Spring context life-cycle aware in-memory database, the DB might not get cleaned-up between test runs.
In your case, the entity you provide simply has the id set. If you don't supply a newly created entity, the persist operation will fail.
So, make sure the entity id is null when you pass it to persist.
Upvotes: 1