1 Reply Latest reply on May 8, 2011 8:26 AM by Leo van den berg

    NoEntityException closes JTA transaction

    GIOVANNI ROBERTO MACHADO Newbie
      Hi, guys

      I gotta go through a resultset retrieaving some data from another table, setting an attibute on an object and persisting it. My problem is: when that search on that second table is not ok, I receive a NoResultException and, after that, every time I try to access the database I receive a "transaction is not active" error. Does anybody have a clue?

      Here is a non-functional piece of the code. I hope it helps somebody to help me.

      do {
            Peca obj = new Peca();
      obj.setCodigoCompleto(rsPrincipal.getString("CODIGO"));
      obj.setDescricao(rsPrincipal.getString("DESCRICAO"));

      // before searching, check the cache hashmap
      ProdutoNCM objProdutoNCM = hsNCM.get(rsPrincipal.getString("NCM_CODIGO").trim().toUpperCase());
            if (objProdutoNCM==null){
        // no object in the hashmap, search table
        try{

         objProdutoNCM = produtoNCMBO.buscarPorCodigoNCM(rsPrincipal.getString("NCM_CODIGO").trim().toUpperCase());

         // record found, put into the hashmap
         hsNCM.put(rsPrincipal.getString("NCM_CODIGO").trim().toUpperCase(), objProdutoNCM);

        }catch( NoResultException e ){
         System.out.println("NCM NAO ENCONTRADO: "+rsPrincipal.getString("NCM_CODIGO").trim().toUpperCase());
         // Here's my problem. After this point, transaction closes.
        }
      }
            obj.setProdutoNCM(objProdutoNCM);
            entityManager.persist(obj);
      entityManager.flush(); // Here I get the stacktrace listed below.

      } while (rsPrincipal.next());






      01:22:31,723 ERROR [application] javax.persistence.TransactionRequiredException: no transaction is in progress
      javax.faces.el.EvaluationException: javax.persistence.TransactionRequiredException: no transaction is in progress
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      at javax.faces.component.UICommand.broadcast(UICommand.java:387)
      at org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)
      at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:329)
      at org.ajax4jsf.component.AjaxViewRoot.broadcastEventsForPhase(AjaxViewRoot.java:304)
      at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:261)
      at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:474)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
      at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
      at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
      at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
      at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:636)


      10x in advance for any help (and sorry about my terrible english)