1 Reply Latest reply on Sep 14, 2007 3:21 PM by cb1

    create and finder in one transaction

    cb1

      Hi There,

      we want to port a WebSphere 6 application to JBoss 4.0.4.GA. The application is designed SOA like. I.e., very often within one transaction an order is created in an OrderService and in the same transaction a request is created in the RequestService calling an order finder Method with orderNumber and mandatorId passed through an OrderDTO to the request create method. Unfortunately, the order cannot be found. WebSphere first searches the order in the container before asking the DB. JBoss seams to search first in the DB where the order cannot be found, of course. Probably, the finder would succeed if the create can be done after ejb-create is done, but we must use the configuration option <insert-after-ejb-post-create>true</insert-after-ejb-post-create> because we first have some non-null fields in the order database table. By the way, we use Oracle 9i.
      The main exception is

      org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=cb-nx7010/343, BranchQual=, localId=343] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=f46486c5c0a8026501808ae8cb7e8d6d); - nested throwable: (org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=cb-nx7010/343, BranchQual=, localId=343] status=STATUS_NO_TRANSACTION; - nested throwable: (javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0, id=f46486c5c0a8026501808ae8cb7e8d6d));

      Turning on the configuration option <call-logging>true</call-logging> we find that a finder exception occurs in the RequestService where the order is searched by orderNumber and mandatorId:
      13:46:44,003 INFO [LogInterceptor] Application Exception in method: public abstract com.wn.pve.ordermgmt.common.entity.Order com.wn.pve.ordermgmt.common.entity.OrderHome.findOrderByOrdernumberAndMandator(java.lang.String,java.lang.String) throws javax.ejb.FinderException
      javax.ejb.ObjectNotFoundException: No such entity!
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCFindEntityCommand.execute(JDBCFindEntityCommand.java:64)
       at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.findEntity(JDBCStoreManager.java:604)
       at org.jboss.ejb.plugins.CMPPersistenceManager.findEntity(CMPPersistenceManager.java:315)
       at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.findEntity(CachedConnectionInterceptor.java:236)
       at org.jboss.ejb.EntityContainer.findSingleObject(EntityContainer.java:1103)
       at org.jboss.ejb.EntityContainer.findLocal(EntityContainer.java:669)
       at sun.reflect.GeneratedMethodAccessor150.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.invocation.Invocation.performCall(Invocation.java:359)
       at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1130)
       at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:105)
       at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:203)
       at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:189)
       at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:105)
       at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:134)
       at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:76)
       at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:43)
       at org.jboss.ejb.plugins.CallValidationInterceptor.invokeHome(CallValidationInterceptor.java:56)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:125)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:435)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:161)
       at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:145)
       at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:132)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:107)
       at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:514)
       at org.jboss.ejb.Container.invoke(Container.java:975)
       at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyFactory.java:359)
       at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:133)
       at $Proxy195.findOrderByOrdernumberAndMandator(Unknown Source)
       at com.wn.pve.ordermgmt.orderservice.logic.requestattachment.PreScope.createRequestForOrderWithScopeAndServiceProvider(PreScope.java:525)
       at com.wn.pve.ordermgmt.orderservice.logic.requestattachment.PreScopeProvisionTransportHandling.createRequestForOrder(PreScopeProvisionTransportHandling.java:49)
       at com.wn.pve.ordermgmt.orderservice.logic.requestattachment.PreScope.create(PreScope.java:330)
       at com.wn.pve.ordermgmt.orderservice.logic.requestattachment.PreScope.adapt(PreScope.java:97)
       at com.wn.pve.ordermgmt.orderservice.logic.requestattachment.OrderRequestAttacher.updateLinkeRequestsForOrder(OrderRequestAttacher.java:94)
       at com.wn.pve.ordermgmt.orderservice.OrderServiceBean.createAdHocOrder(OrderServiceBean.java:568)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.invocation.Invocation.performCall(Invocation.java:359)
       at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:237)
       at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:158)
       at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:169)
       at org.jboss.ws.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:64)
       at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63)
       at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121)
       at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:350)
       at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
       at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:168)
       at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
       at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:136)
       at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:648)
       at org.jboss.ejb.Container.invoke(Container.java:954)
       at sun.reflect.GeneratedMethodAccessor151.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
       at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
       at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
       at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
       at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
       at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(LocalInvoker.java:169)
       at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:118)
       at org.jboss.invocation.InvokerInterceptor.invokeLocal(InvokerInterceptor.java:206)
       at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:192)
       at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:61)
       at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:70)
       at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:112)
       at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:100)
       at $Proxy445.createAdHocOrder(Unknown Source)
       at com.wn.pve.ordermgmt.delegate.rmi.OrderServiceDelegate.createAdHocOrder(OrderServiceDelegate.java:164)
       at com.wn.pve.wd.ordermgmt.adhoc.AdHocOrderActionImpl.onBtnSaveClicked(AdHocOrderActionImpl.java:315)
       at com.wn.pve.wd.ordermgmt.adhoc.AdHocOrderAction.save_onClick(AdHocOrderAction.java:265)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:324)
       at com.cc.framework.adapter.struts.ActionUtil.handleFormAction(ActionUtil.java:521)
       at com.cc.framework.adapter.struts.FWAction.handleFormAction(FWAction.java:203)
       at com.cc.framework.adapter.struts.ActionUtil.execute(ActionUtil.java:636)
       at com.cc.framework.adapter.struts.FWAction.execute(FWAction.java:268)
       at com.cc.framework.adapter.struts.FWAction.execute(FWAction.java:298)
       at com.cc.framework.adapter.struts.RequestProcessorUtil.processAction(RequestProcessorUtil.java:78)
       at com.cc.framework.adapter.struts.FWRequestProcessor.processActionPerform(FWRequestProcessor.java:90)
       at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
       at com.wn.pve.wd.mcf.MCFRequestProcessor.process(MCFRequestProcessor.java:113)
       at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
       at com.wn.pve.wd.mcf.MCFActionServlet.process(MCFActionServlet.java:69)
       at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
       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 com.wn.pve.wd.mcf.SessionFilter.doFilter(SessionFilter.java:85)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       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.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       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:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       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:534)


      Thanx for your help!

        • 1. Re: create and finder in one transaction
          cb1

          I located the problem. Probably, it is a JBoss Bug, but I was able to bypass it in our code.
          The problem was the following. Within one transaction we created a new entity in the OrderService:

          ...
          orderEntity = EntityHomeHelper.getOrderHome().create(....); // it is important that the madatorname was NOT passed in the create method.
          orderEntity.setMandatorname(getMandatorName()); // it is set right afterwards.
          ...

          Then, in the RequestService - within the same transaction - the following finder was used to find the previous created order entity:
          findOrderByOrdernumberAndMandator(java.lang.String,java.lang.String)

          The finder failed as described in the posting.
          But, when looking for all orders, the entity was found.
          try {
           Collection col = EntityHomeHelper.getOrderHome().findAll();
           for (Iterator iter = col.iterator(); iter.hasNext();) {
           Order element = (Order) iter.next();
           System.out.println("MandatorName: " + element.getMandatorname());
           }
          } catch (FinderException finderException) {
           // ignore: it is just for testing
          }


          Thus, I was wrong in the forum posting guessing that JBoss does not look first in the bean cache when calling a finder.

          What I did to fix the problem is the following. I extended the create method of the order entity by mandatorname. If it is passed within the create method and, of course, set there by the setMandatorname method, it works as expected. I.e, the finder finds the entity created in the transaction.
          ...
          orderEntity = EntityHomeHelper.getOrderHome().create(..., getMandatorName());
          ...