[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Optimistic Lock Exception expected

I'm answering on behalf of Mathias as he's on vacation for 2 weeks.

James Sutherland schrieb:
A lock error should occur on your merge() call, it is unexpected if it does
As far as I have heard a lock error does *not* occur.
Ensure that you have an @Version in your object.
We have an @Version in our object(s)!
If still not getting the
error please include the code for your class and the log on finest of your
Please note that our code (unmodified) worked as (we) expected with an older TopLink Essentials version
(see below). Does that give you a clue on the root cause of the problem already? If not we'll provide the
requested information when Mathias is back from vacation.

Thanks in advance,

Mathias Koehnke - Sun Microsystems wrote:

while replacing Toplink Essentials (2.0.1-b04-fcs (04/11/2008)) by EclipseLink 1.1 for a Java SE project, I came across a problem that prevents me from switching: I would expect getting an Optimistic Lock exception in case an entity gets removed from the database (by another thread or whatever) and one tries to commit on a still-existing runtime object of that entity. That was my expectation and it worked with Toplink Essentials so far. Using EclipseLink it doesn't throw an OL exception, instead the entity gets re-inserted in the database.

Am I using JPA/EclipseLink the wrong way or do I miss something? From my understanding the following example should throw an OL exception when committing the last transaction:

Entity entity = new Entity();

//persist "entity" and create clone "entityCopy"
EntityManager em1 = getEntityManagerFactory().createEntityManager();
Entity entityCopy = em1.find(Entity.class, entity.getId());

//delete "entity" from database
EntityManager em2 = getEntityManagerFactory().createEntityManager();
entity = em2.merge(entity);

//merge clone "entityCopy" and commit
EntityManager em3 = getEntityManagerFactory().createEntityManager();
entityCopy = em3.merge(entityCopy);
em3.lock(entityCopy, LockModeType.WRITE);

Note: I already added a SessionCustomizer modifying the session the following way:


So, EclipseLink shouldn't check the database for the existence of the entity at all. Instead it should assume that the entity exists and simply execute an "UPDATE ..." sql statement.

Thanks for your help in advance.

Best regards,
Mathias Koehnke

http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland http://www.eclipse.org/eclipselink/
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
TopLink Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink , http://wiki.oracle.com/page/TopLink TopLink Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , http://www.nabble.com/EclipseLink-f26430.html EclipseLink Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence

Sun Microsystems GmbH Tino Rachui
Nagelsweg 55 Desktop Virtualisierung
Hamburg Sun Ray Entwicklung
Germany Phone: +49(0)40 23646928


Sitz der Gesellschaft: Sun Microsystems GmbH, Sonnenallee 1,
D-85551 Kirchheim-Heimstetten
Amtsgericht Muenchen: HRB 161028
Geschaeftsfuehrer: Thomas Schröder, Wolfgang Engels, Dr. Roland Boemer
Vorsitzender des Aufsichtsrates: Martin Haering