Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Merge does an undesirable persist
Merge does an undesirable persist [message #710278] Thu, 04 August 2011 21:52 Go to next message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
Registered: September 2009
Location: Brasil
The method merge of an entitymanager persist the entity when it doesn't exist.
This can be a problem in a concurrent environment.

An expected updating operation...

1) foo = em.find(
2) if (foo != null) // the entity exists!!!
3) em.merge(foo)

can result in an insert, if between lines 2 and 3 the entity foo is deleted by another user.

Can I configure merge to throw an exception when the entity does not exist?

Thanks. Mauro.
Re: Merge does an undesirable persist [message #710842 is a reply to message #710278] Fri, 05 August 2011 13:23 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1382
Registered: July 2009
Senior Member
This is by design to allow attaching new entities to existing object graphs and then merge only the root. The only way to prevent writing of overwriting with stale data is to use optimistic locking (an @Version field) which would throw an exception when a new object already has a lock value.

Best Regards,
Previous Topic:(no subject) duplicate, please ignore topic
Next Topic:(no subject)
Goto Forum:

Current Time: Mon Apr 12 23:36:48 GMT 2021

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

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

Back to the top