1 Reply Latest reply on Jul 5, 2011 7:07 AM by davidmiller

    JDBCExceptionReporter Transaction is not active:

    davidmiller

      Hi,
      I wonder if you can help me.


      I have a @Observer method to catch when an Exception happens, and I aim to log some details to a database when an Exception happens.


      However I get an

      14:52:13,837 ERROR [JDBCExceptionReporter] Transaction is not active: tx=TransactionImple < ac, BasicAction: -3f57ff44:cf38:4e09dc68:e1 status: ActionStatus.ABORT_ONLY >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: -3f57ff44:cf38:4e09dc68:e1 status: ActionStatus.ABORT_ONLY >)


      'JDBCExceptionReporter Transaction is not active:' error when I try and access the database.  I'm assuming because an exception has been thrown then then any transaction the Seam framework is in will be in the process of being rolled back.  Is there a way of creating a new transaction, or am I missing something fundamental.


      Here is my code:


      @Name("exceptionInterceptor")
      public class ExceptionInterceptor implements ExceptionInterceptorI {
          @Logger
          protected transient Log log;
      
          @In(required = true)
          EntityManager entityManager;
      
          @Override
          @Observer({ "org.jboss.seam.async.asynchronousExceptionHandler", "org.jboss.seam.exceptionHandled", "org.jboss.seam.exceptionNotHandled" })
          public void onError(Exception throwable) {
      
              Query query = entityManager.createNativeQuery("select * from company where id_com = 8");
      
              query.getResultList();
      
          }
      
          private HttpServletRequest getRequest() {
              return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
          }
      
      }


        • 1. Re: JDBCExceptionReporter Transaction is not active:
          davidmiller

          I got the answer for this, so thought I would post my solution to hopefully help others in the future.


          I changed the code as follows, making it a stateless bean and adding a transaction attribute(TransactionAttributeType.REQUIRES_NEW) to the action method:


          @Stateless
          @Name("exceptionInterceptor")
          public class ExceptionInterceptor implements ExceptionInterceptorI {
              @Logger
              protected transient Log log;
          
              @In(required = true)
              EntityManager entityManager;
          
              @Override
              @Observer({ "org.jboss.seam.async.asynchronousExceptionHandler", "org.jboss.seam.exceptionHandled", "org.jboss.seam.exceptionNotHandled" })
              @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
              public void onError(Exception throwable) {
          
                  Query query = entityManager.createNativeQuery("select * from company where id_com = 8");
          
                  query.getResultList();
          
              }
          
              private HttpServletRequest getRequest() {
                  return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
              }
          
          }




          Hope that helps someone.



          Feel like I'm talking to myself...