I am trying JPA's support of database locking in order to avoid concurrent requests in a record. In my scenario I need to use a pesssimistic lock. I got that using the following approach:
EntityManager em;
...
Map<String,Object> props = new HashMap<String,Object>();
props.put("javax.persistence.lock.timeout", 0);
em.find(MyEntity.class, id, LockModeType.PESSIMISTIC_READ, props)
but with that approach I handle a LockTimeoutException instead of a PessimisticLockException. How to handle a PessimisticLockException specifically?