1 Reply Latest reply on Jun 20, 2012 10:24 AM by gebuh

    persisting exception information to db after transaction exceptions

    gebuh Newbie

      I'm trying to save seam generated exceptions in our (war, pojo)application.  So when a when a org.jboss.seam.async.asynchronousExceptionHandler, org.jboss.seam.exceptionHandled,  or org.jboss.seam.exceptionNotHandled exception(though ideally I'd like to catch any exceptions)  raises an event I have an Observer method that creates a UserStatsData entity in a session scoped bean and persists it to the database - in theory, I haven't been able to get it to work. 

      I've tried entityManager.persist/merge(breaks when I call flush),  createNativeQuery(both generate TransactionRequiredException), even UserTransaction(generates javax.transaction.NotSupportedException) with and without @Transactional set on this method.  I get varying error messages but nothing seems to be working. 

      I think the problem might be related to the type of original exception raised - a user who doesn't have data in the database tries to access that nonexistent row using getSingleResult, this causes a javax.persistence.NoResultException.  Could it be possible that that exception has put the persistence context in some sort of inbetween state causing issues with flush immediately afterwards?

      Any help is appreciated.

        • 1. Re: persisting exception information to db after transaction exceptions
          gebuh Newbie

          after much googling I found the problem.  When the original exception is raised Seam marks the transaction for rollback.  Because Seam doesn't have a way to require a new transaction (there's a Jira for this that has a patch attached but appears to be in limbo) and my method is called in the same transaction(I tried annotating it with Asynchronous, but didn't work) it blows up.

          What I ended up doing - and I don't know if I'm creating a whole new problem was add this:

          if(userTx.isRolledBackOrMarkedRollback()) {


          inside my addExceptions method before I persist the exceptions data.