Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] [ClassName] cannot be merged because it has changed or been deleted since it was last read

Two mistakes in a row :(

If I understand it correctly, merge() works for both persistent and
transient (non-persistent) entities. The reason this was failing for me is
that the database already contained an entity with the ID I was trying to
save bu the database entity had a "version" of 1 while the entity I was
trying to save had a "version" of 0. To fix the problem my transient entity
needs a "version" of 2 or higher to indicate it has changed and is newer
than the database version.

Sorry for the confusion.


cowwoc wrote:
> Turns out this was my mistake. I was trying to merge() a non-persistent
> object.
> This brings up the question, is there a method that takes in an Entity and
> calls persist() if it's non-persistent and merge() if it is? Sort of like
> Hibernate's Session.saveOrUpdate() method.
> Thanks,
> Gili
> cowwoc wrote:
>> Hi,
>> I retrieve an Entity from the DB, modify it then invoke
>> EntityManager.merge() on it. For some reason EclipseLink throws this
>> exception:
>> javax.persistence.OptimisticLockException: Exception [EclipseLink-5010]
>> (Eclipse Persistence Services - 1.0 (Build 1.0 - 20080707)):
>> org.eclipse.persistence.exceptions.OptimisticLockException
>> Exception Description: The object [Object.toString() goes here] cannot be
>> merged because it has changed or been deleted since it was last read.
>> {3}Class> [className goes here]
>> I'm confused. Isn't the entire point of EntityManager.merge() to push
>> changes from the in-memory entity back to the database? Shouldn't this
>> work?
>> Thank you,
>> Gili

View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top