OptimisticLock: exception stack differs for value > version and value < version [message #1547761] |
Mon, 05 January 2015 16:30 |
Sebastian Bartholomäus 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:
- javax.ejb.EJBException
- Caused by: javax.persistence.OptimisticLockException:
- 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:
- javax.ejb.EJBException
- Caused by: javax.transaction.RollbackException: Transaction marked for rollback.
- Caused by: javax.persistence.OptimisticLockException:
- 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.10142 seconds