4 Replies Latest reply on Sep 18, 2006 6:29 AM by Mohit Bajaj

    Problem in Transaction handling

    Mohit Bajaj Newbie

      Hi,

      I am using Jboss and Toplink. I am using external transaction controller (JBoss). I am not able to do the transaction with this code:

      try
      {
      //clientSession = getClientSession();
      poId = poHeader.getPoId();
      poVersion = poHeader.getPoVersion();
      poNumber = poHeader.getPoNo();
      Collection partyCollection = poHeader.getPartyCollection();

      //Check for data change(cuncurrency) in-between : Start
      /*
      ExpressionBuilder builder = new ExpressionBuilder();
      Expression wcPO = builder.get("poId").equal(poId).and(builder.get("poVersion").equal(poVersion)).and(
      builder.get("orderType").equal("S"));
      POHeader poHeaderCurrent = (POHeader)clientSession.readObject(POHeader.class,wcPO);
      //Vector currPOHeader = (Vector)clientSession.executeQuery("select mod_date_time from pix_po_header where po_id="+poId+" and po_version="+poVersion+" and active_flag='Y' and order_type='S'");

      if(poHeader.getModDateTime().before(poHeaderCurrent.getModDateTime()))
      {
      AppException ae = new AppException();
      ae.performErrorAction(Exceptions.DATA_CUNCURRENCY, "PurchaseOrderDAOImpl,insertOrderConfirmation");
      throw ae;
      }

      clientSession.release();
      */
      //Check for data change(cuncurrency) in-between : End

      for(int i=0;i<partyCollection.size();i++){
      poParty = (POParty)((Vector)partyCollection).get(i);

      if((PIXConstants.VENDOR_ROLE).equals(poParty.getPartyType()))
      {
      deliveryDate = poParty.getDeliveryDate();
      deliveryDate = PIXUtil.standardToSqlDate(deliveryDate);
      if(deliveryDate==null){
      deliveryDate = "";
      }
      comments = poParty.getComments();
      vendorStatusId = poParty.getStatusId();
      vendorModifiedBy = poParty.getModifiedBy();
      }
      }
      //clientSession.executeNonSelectingCall(new SQLCall("SET AUTOCOMMIT OFF"));
      /////uow = clientSession.getActiveUnitOfWork();
      //uow.beginEarlyTransaction();
      Context ctx = new InitialContext(null);
      DataSource ds = (DataSource) ctx.lookup("OracleDB");

      uow = (UserTransaction)ctx.lookup("UserTransaction");

      uow.begin();
      //checkUserTransaction(ut);
      conn = ds.getConnection();
      Statement stmt = conn.createStatement();
      stmt.executeUpdate("update PIX_PO_HEADER set "
      +"status_id="+poHeader.getStatusDetail().getStatusId()+","
      +"acknowledge_flag='Y',"
      +"mod_date_time=sysdate,"
      +"modified_by='"+poHeader.getModifiedBy()+"' "
      +"where po_id="+poId+" and po_version="+poVersion);
      stmt.executeUpdate("update PIX_PO_PARTY set "
      +"status_id="+vendorStatusId+","
      +"delivery_date='"+deliveryDate+"',"
      +"comments='"+comments+"' "
      +"where po_id="+poId+" and po_version="+poVersion+" and party_type='V'");

      Collection lineItemCollection = poHeader.getLineItemCollection();
      for(int i=0;i<lineItemCollection.size();i++){
      poLine = (POLine)((Vector)lineItemCollection).get(i);
      supplierStatusId = poLine.getSupplierStatusId();
      estimatedDeliveryDate = poLine.getEstimatedDeliveryDate();
      estimatedDeliveryDate = PIXUtil.standardToSqlDate(estimatedDeliveryDate);
      if(estimatedDeliveryDate==null){
      estimatedDeliveryDate = "";
      }
      supplierComments = poLine.getSupplierComments();
      stmt.executeUpdate("update PIX_PO_LINE set "
      +"supplier_status_id="+supplierStatusId+","
      +"estimated_delivery_date='"+estimatedDeliveryDate+"',"
      +"supplier_comments='"+supplierComments+"',"
      +"mod_date_time=sysdate,"
      +"modified_by='"+poLine.getModifiedBy()+"' "
      +"where po_id="+poId+" and po_version="+poVersion+" "
      +"and po_line_no="+poLine.getPoLineNo());
      }
      uow.commit();
      }
      catch(TopLinkException te)
      {
      AppException ae = new AppException();
      ae.performErrorAction(Exceptions.SQL_EXCEPTION,"PurchaseOrderDAOImpl,insertOrderConfirmation",te);
      throw ae;
      }
      catch(NamingException ne)
      {
      AppException ae = new AppException();
      ne.printStackTrace();
      ae.performErrorAction(Exceptions.SQL_EXCEPTION,"PurchaseOrderDAOImpl,insertOrderConfirmation",ne);
      throw ae;
      }
      catch(Exception e)
      {
      AppException ae = new AppException();
      e.printStackTrace();
      ae.performErrorAction(Exceptions.SQL_EXCEPTION,"PurchaseOrderDAOImpl,insertOrderConfirmation",e);
      throw ae;
      }
      finally
      {
      try
      {
      uow.rollback();
      }
      catch(Throwable tu)
      {
      throw new RuntimeException(tu);
      }
      }



      When the above mentioned code is executed, I get the following exception:

      12:23:22,831 INFO [STDOUT] javax.transaction.NotSupportedException: Transaction already active, cannot nest transactions.
      12:23:22,831 INFO [STDOUT] at org.jboss.tm.TxManager.begin(TxManager.java:193)
      12:23:22,831 INFO [STDOUT] at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.begin(ServerVMClientUserTransaction.java:110)
      12:23:22,831 INFO [STDOUT] at com.pearson.pix.dao.purchaseorder.PurchaseOrderDAOImpl.insertOrderConfirmation(PurchaseOrderDAOImpl.java:478)
      12:23:22,831 INFO [STDOUT] at com.pearson.pix.business.purchaseorder.ejb.PurchaseOrderEJB.saveOrderConfirmation(PurchaseOrderEJB.java:179)
      12:23:22,831 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      12:23:22,831 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      12:23:22,831 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      12:23:22,831 INFO [STDOUT] at java.lang.reflect.Method.invoke(Method.java:585)
      12:23:22,831 INFO [STDOUT] at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
      12:23:22,831 INFO [STDOUT] at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
      12:23:22,831 INFO [STDOUT] at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.Container.invoke(Container.java:873)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:415)
      12:23:22,831 INFO [STDOUT] at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:88)
      12:23:22,831 INFO [STDOUT] at $Proxy82.saveOrderConfirmation(Unknown Source)
      12:23:22,831 INFO [STDOUT] at com.pearson.pix.presentation.purchaseorder.delegate.PurchaseOrderDelegate.saveOrderConfirmation(PurchaseOrderDelegate.java:69)
      12:23:22,831 INFO [STDOUT] at com.pearson.pix.presentation.purchaseorder.command.PurchaseOrderCommand.executeInsert(PurchaseOrderCommand.java:426)
      12:23:22,831 INFO [STDOUT] at com.pearson.pix.presentation.base.action.BaseAction.execute(BaseAction.java:93)
      12:23:22,847 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
      12:23:22,847 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
      12:23:22,847 INFO [STDOUT] at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
      12:23:22,847 INFO [STDOUT] at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
      12:23:22,847 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      12:23:22,847 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      12:23:22,847 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      12:23:22,847 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      12:23:22,847 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
      12:23:22,847 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      12:23:22,847 INFO [STDOUT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      12:23:22,847 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      12:23:22,847 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      12:23:22,847 INFO [STDOUT] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      12:23:22,847 INFO [STDOUT] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      12:23:22,847 INFO [STDOUT] at java.lang.Thread.run(Thread.java:595)
      12:23:22,894 INFO [STDOUT] {OFFERSHEET_IMAGE_SIZE_KB=521, THUMBNAIL_QUALITY=50, PROVIDER_URL=t3://localhost:8080, THUMBNAIL_WIDTH=200, ATTACHMENT_MAX_SIZE_IN_KB=2048, THUMBNAIL_HEIGHT=150, PIX_LOG_FILE_PATH=c:\mydomain, OFFERSHEET_IMAGE_DIMENSION2=480, OFFERSHEET_IMAGE_DIMENSION1=640}
      12:23:23,050 ERROR [LogInterceptor] RuntimeException in method: public abstract java.lang.String com.pearson.pix.business.purchaseorder.interfaces.PurchaseOrderLocal.saveOrderConfirmation(com.pearson.pix.dto.purchaseorder.POHeader) throws com.pearson.pix.exception.AppException:
      java.lang.IllegalStateException: Wrong transaction association: expected TransactionImpl:XidImpl[FormatId=257, GlobalId=hddlntdmt00636/23, BranchQual=, localId=23] was null
      at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:471)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:346)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
      at org.jboss.ejb.Container.invoke(Container.java:873)
      at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:415)
      at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:88)
      at $Proxy82.saveOrderConfirmation(Unknown Source)
      at com.pearson.pix.presentation.purchaseorder.delegate.PurchaseOrderDelegate.saveOrderConfirmation(PurchaseOrderDelegate.java:69)
      at com.pearson.pix.presentation.purchaseorder.command.PurchaseOrderCommand.executeInsert(PurchaseOrderCommand.java:426)
      at com.pearson.pix.presentation.base.action.BaseAction.execute(BaseAction.java:93)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      at java.lang.Thread.run(Thread.java:595)


      Please let me know what all settings are required in JBoss to run the transactions.

      Thanks in advance !