Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » OptimisticLock: exception stack differs for value > version and value < version
OptimisticLock: exception stack differs for value > version and value < version [message #1547761] Mon, 05 January 2015 16:30 Go to next message
Sebastian Bartholomäus is currently offline Sebastian BartholomäusFriend
Messages: 1
Registered: April 2014
Junior Member
While testing the OptimisticLock i found out that the actual exception stack differs depending on the value of the version attribute of the entity to be written.

If the version value in the entity is less than the version value in the DB, the exception stack looks like this:

  1. javax.ejb.EJBException
  2. Caused by: javax.persistence.OptimisticLockException:
  3. Caused by: Exception [EclipseLink-5010] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.OptimisticLockException

If the version value in the entity is greater than the version value in the DB, the exception stack looks like this:

  1. javax.ejb.EJBException
  2. Caused by: javax.transaction.RollbackException: Transaction marked for rollback.
  3. Caused by: javax.persistence.OptimisticLockException:
  4. Caused by: Exception [EclipseLink-5010] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.OptimisticLockException

Is this the intended behavior? It might be a corner case that a client sends a version id that is greater than the one on the server, but I still would like to handle both cases; and the different exception stacks force me to implement different (JAX-RS) ExceptionMappers.

Also this might lead some to the assumption that in the first case the transaction was not rolled back (although it definitely is, due to javax.persistence.OptimisticLockException being a system exception).

Environment:

  • I'm using EclipseLink through JPA in a Java8 + JavaEE7 application on a glassfish 4.1.
  • I'm using Container Managed Transactions.

Setup:

  • I use a simple Long with the @Version annotation as an OptimisticLock for an Entity (User).
  • An EJB (UserManager) offers a method ( updateUser(User user) { ... } ) to write the entity to the DB.
  • A client (REST Service) calls the EJB with different User instances.

[Updated on: Tue, 06 January 2015 07:30]

Report message to a moderator

Re: OptimisticLock: exception stack differs for value > version and value < version [message #1553408 is a reply to message #1547761] Thu, 08 January 2015 17:37 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Both cases cause the transaction to rollback.
This is a consequence as to where the exception is being thrown from. In the first case, it seems EclipseLink is able to detect that the versions are different upfront, and so throw the exception itself (and mark the transaction for rollback). In the second, it occurs when it is accessing the database, likely within a transction beforeCompletion method, in which case the exception it throws is caught by the container and wrapped in the javax.transaction.RollbackException.
Previous Topic:IN with subquery
Next Topic:JMS Cache Coordination help with NON-JPA deployments
Goto Forum:
  


Current Time: Tue Mar 19 09:02:17 GMT 2024

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

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

Back to the top