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 Flores
Messages: 84
Registered: September 2009
Location: Brasil
Member
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(foo.id)
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 Delahunt
Messages: 1034
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,
Chris
Previous Topic:(no subject) duplicate, please ignore topic
Next Topic:(no subject)
Goto Forum:
  


Current Time: Sun Oct 26 05:24:32 GMT 2014

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

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