users@glassfish.java.net

Re: Unexpected Behavior: NoResultException rolls back transaction

From: <glassfish_at_javadesktop.org>
Date: Mon, 28 Jan 2008 08:36:21 PST

mmichalak: Thanks for giving a great explaination.

zebhed:
 The addition is neccessary since it is describing JPA functionality, not the container behaviour. PersistenceExceptions and OptimititicLockExceptions are two examples of exceptions the JPA provider will throw that will cause the provider to mark the transaction for rollback. This essentially means that if your application catches one of these exceptions from the point they are originally thrown, the transaction is already marked for rollback. If your app catches a NoResultException from the point it is thrown (ie from the getSingleResult call), the transation will still be active. If your code doesn't catch it and allows it to go the container, the container has to assume the transaction is incomplete (it encountered a RuntimeException) and so marks it for rollback.

The container behaviour is completely independent of the comment and JPA behaviour in general. The container will not distinguish between any RuntimeException, as any mean that the transaction did not complete successfully and should be rolledback.

Regards
[Message sent by forum member 'chris_delahunt' (chris_delahunt)]

http://forums.java.net/jive/thread.jspa?messageID=256146