Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Issue with new entities after delete then merge
Issue with new entities after delete then merge [message #1161428] Tue, 29 October 2013 20:14 Go to next message
Rob Young is currently offline Rob YoungFriend
Messages: 3
Registered: October 2013
Junior Member
My group has been noticing an intermittent issue for a while on our integration tests, where we are testing a REST service that is basically a layer to JPA entities. The issue is that in thread A an Entity S is deleted, while in thread B we are logging some data to S, in sub tables (Entities). What we're seeing is Entity S is being deleted, but a new entity T is created. The subtable data in thread B is using the merge call, as we are updating an existing record.

What I think is happening, is that S is becoming detached from EclipseLink, and then when merge is called on it's sub entity, it is creating a new record. Is this a likely assumption? What I would like to happen is for the entity manager to throw an exception when I call merge on these now invalid sub children, as their parent is no longer valid in the system.

For what it's worth, the Entity S has cascade = CascadeType.ALL set for it's mappings to it's sub entities, but the sub entities do not have this defined for the link back to S.

Should I be using @PrivateOwned for the children of S?
Re: Issue with new entities after delete then merge [message #1164153 is a reply to message #1161428] Thu, 31 October 2013 13:20 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
The merge is required to persist new entities, and since the entity was deleted in a prior transaction, it is effectively new. You need to be using optimistic locking to prevent overwriting existing data (the delete) with stale data (your deleted entity). Optimistic locking such as using a version field would allow EclipseLink to see that the object you are calling merge on already has a version and so isn't new, allowing EclipseLink to throw an exception if the entity doesn't exist.
Re: Issue with new entities after delete then merge [message #1173951 is a reply to message #1164153] Wed, 06 November 2013 21:27 Go to previous messageGo to next message
Rob Young is currently offline Rob YoungFriend
Messages: 3
Registered: October 2013
Junior Member
Thanks Chris, I finally got around to writing some test code and then adding the version field to my entity. This solved my problems!
Re: Issue with new entities after delete then merge [message #1175085 is a reply to message #1173951] Thu, 07 November 2013 14:14 Go to previous message
Rob Young is currently offline Rob YoungFriend
Messages: 3
Registered: October 2013
Junior Member
As a broader question, is it best practice to add a @Version field to every entity in a multithreaded JPA application? Are there any negative side effects to doing so?
Previous Topic:Why are you not using java.util.concurrent classes?
Next Topic:SQL Exception not being caught
Goto Forum:
  


Current Time: Fri Apr 19 21:59:24 GMT 2024

Powered by FUDForum. Page generated in 0.03245 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top