The JPA Spec states defines five exceptions for JPA providers to raise, see below. However, the OpenJPA buries these exceptions undeterministic number of levels of nested exceptions, i.e. not obvious how many times I need to catch throwable using ex.getCause().
Am I missing something ? All I am trying to find out is that if the transaction is rolled back because of the fact that the entity already exists programmatically. Is there a way to deterministically find out this programmatically, how many level deep I have to go to catch standard JPA exceptions In OpenJPA? Gul EntityExistsException : Thrown by the persistence provider when EntityManager.persist(Object) is called and the entity already exists. EntityNotFoundException : Thrown by the persistence provider when an entity reference obtained by EntityManager.getReference(Class,Object) is accessed but the entity does not exist. NonUniqueResultException : Thrown by the persistence provider when getSingleResult() is executed on a query and there is more than one result from the query. NoResultException : Thrown by the persistence provider when getSingleResult() is executed on a query and there is no result to return. OptimisticLockException : Thrown by the persistence provider when an optimistic locking conflict occurs. PersistenceException : Thrown by the persistence provider when a problem occurs. RollbackException : Thrown by the persistence provider when the EntityTransaction.commit() fails. TransactionRequiredException : Thrown by the persistence provider when a transaction is required but is not active.
