• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is a PersistenceException per default a system exception?

 
Christian Heldstab
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Is a PersistenceException per default a system exception?

As I read from specification, EJB system exceptions are RemoteExceptions and RuntimeExceptions.

On the other hand, all PersistenceExceptions extends RuntimeException and rolls a transaction back (excluding NonUniqueResultException and NoResultException).

So does it is correct that PersistenceExceptions are EJB system exceptions as long as there is nothing else sp´┐Żecified with an annotation or in deployment descriprot?

Christian
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right. PersistenceException is a RuntimeException and as such is a system exception from the EJB Container's point of view. However, don't forget that it is NOT an EJBException.

If your application uses session or mesage-driven beans and a call to an EntityManager method throws a PersistenceException (and if the bean rethrows that exception), the EJB Container will wrap the exception in an EJBException and rethrow it to the bean's client. Also, the bean will be discarded (as it is a system exception) and the transaction will be rolled back: in all cases(!), even if the PersistenceException was in fact a NonUniqueResultException or NoResultException. The reason behind that is that when the bean rethrows the PersistenceException, that is regarded as a system exception from the EJB Container point of view (and we know what happens with system exceptions).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic