actframework / act-eclipselink

Provide JPA support via EclipseLink
Apache License 2.0
1 stars 1 forks source link

OptimisticLockException could not be catch #5

Closed leeaee closed 6 years ago

leeaee commented 6 years ago

EclipseLink in ACT give a warning log about org.eclipse.persistence.exceptions.OptimisticLockException, but throw java.lang.IllegalStateException at final. So, the OptimisticLockException could not be caught in the program and can get the OptimisticLockException error message.

2018-07-03 11:24:05,198 DEBUG [XNIO-1 task-3] [eclipselink.logging.sql] - UPDATE bb_admin SET last_update = ?, VERSION = ? WHERE ((ID = ?) AND (VERSION = ?))
    bind => [2018-07-03 11:24:05.197, 6, 10, 5]
2018-07-03 11:24:05,202 WARN  [XNIO-1 task-3] [eclipselink.logging.all] - Exception [EclipseLink-5011] (Eclipse Persistence Services - 2.7.1.v20171221-bd47e8f): org.eclipse.persistence.exceptions.OptimisticLockException
Exception Description: One or more objects cannot be updated because it has changed or been deleted since it was last read
2018-07-03 11:24:05,207 ERROR [XNIO-1 task-3] [act.handler.builtin.controller.RequestHandlerProxy] - Error handling request: [PATCH] /api/admin/10
java.lang.IllegalStateException: Not in a TX scope
    at org.osgl.util.E.illegalStateIf(E.java:753)
    at act.db.sql.tx.TxContext.exitTxScope(TxContext.java:66)
    at act.db.sql.tx.TxScopeHelper.exit(TxScopeHelper.java:39)
    at cc.bable.nexus.api.AdminEndpoint.updateAdmin(AdminEndpoint.java:109)

Reproduce step:

  1. Create a JPA entity with @Version
    @Version
    public Long version;
  2. Update the JPA entity with out of date version value For example: version in DB is 3. POST the update version as 2.
leeaee commented 6 years ago

The OptimisticLockException could be caught by RollbackException.getCause() instanceof OptimisticLockException