0 Replies Latest reply on Feb 6, 2007 5:58 PM by Brian Corbett

    Update record problems with EJB3

    Brian Corbett Newbie

      I am having quite a few problems updating a record in a webapp using
      EJB3. I am using JBoss 4.0.5 GA with the EJB3 option installed. The database I am connecting to runs on an ISeries. I can retrieve data lists fine, but I can't seem to change the record. Yes, I do know that my file is journaled.

      I would very much appreciate, if someone could spot something wrong,
      because I am clueless.


      @Stateless
      @Remote(MenuUserController.class)
      public class MenuUserControllerBean implements MenuUserController {
       @PersistenceContext(unitName="menu400")
       EntityManager entityManager;
      
      
       /* (non-Javadoc)
       * @see usermanager.menu400.sessionremote.MenuUserController#updateUser(usermanager.menu400.util.MenuUserDetails)
       */
       @TransactionAttribute(TransactionAttributeType.REQUIRED)
       public void updateUser(MenuUserDetails rec) {
       M4puser req = entityManager.find(M4puser.class, rec.getUser());
       if (req != null) {
      
       if(!rec.getUser().equals(req.getUser().trim())) {
       req.setUser(rec.getUser());
       }
       if (!rec.getRstcpb().equals(req.getRstcpb().trim())) {
       req.setRstcpb(rec.getRstcpb());
       }
       if (!rec.getUserpw().equals(req.getUserpw().trim())) {
       req.setUserpw(rec.getUserpw());
       }
       if (!rec.getUsrsts().equals(req.getUsrsts().trim())) {
       req.setUsrsts(rec.getUsrsts());
       }
       if (!rec.getUname().equals(req.getUname().trim())) {
       req.setUname(rec.getUname());
       }
      
       //entityManager.flush();
       }
       }
      }
      
      


      I get the following exception:
      2007-02-06 16:40:29,403 DEBUG [org.hibernate.impl.SessionImpl] opened session at timestamp: 4795603474034688
      2007-02-06 16:40:29,403 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking for a JTA transaction to join
      2007-02-06 16:40:29,403 DEBUG [org.hibernate.jdbc.JDBCContext] successfully registered Synchronization
      2007-02-06 16:40:29,403 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking for a JTA transaction to join
      2007-02-06 16:40:29,403 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Transaction already joined
      2007-02-06 16:40:29,403 DEBUG [org.hibernate.loader.Loader] loading entity: [usermanager.menu400.entities.M4puser#CHCOPY]
      2007-02-06 16:40:29,403 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
      2007-02-06 16:40:29,403 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
      2007-02-06 16:40:29,403 DEBUG [org.hibernate.SQL] select m4puser0_.user as user2_0_, m4puser0_.umnsty as umnsty2_0_, m4puser0_.brkmq as brkmq2_0_, m4puser0_.atnpgm as atnpgm2_0_, m4puser0_.mnulvl as mnulvl2_0_, m4puser0_.grpmnu as grpmnu2_0_, m4puser0_.setpgm as setpgm2_0_, m4puser0_.usrf3 as usrf8_2_0_, m4puser0_.sysreq as sysreq2_0_, m4puser0_.atnlib as atnlib2_0_, m4puser0_.rstcpb as rstcpb2_0_, m4puser0_.rsttrm as rsttrm2_0_, m4puser0_.menu as menu2_0_, m4puser0_.userpw as userpw2_0_, m4puser0_.usrsts as usrsts2_0_, m4puser0_.uname as uname2_0_, m4puser0_.setlib as setlib2_0_, m4puser0_.usrnpw as usrnpw2_0_, m4puser0_.acctcd as acctcd2_0_, m4puser0_.brktrm as brktrm2_0_, m4puser0_.usrssn as usrssn2_0_, m4puser0_.hlplvl as hlplvl2_0_, m4puser0_.usrnpd as usrnpd2_0_, m4puser0_.brkmql as brkmql2_0_, m4puser0_.userpd as userpd2_0_ from menu400tdi.M4PUSER m4puser0_ where m4puser0_.user=?
      2007-02-06 16:40:29,575 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open ResultSet (open ResultSets: 0, globally: 0)
      2007-02-06 16:40:29,575 DEBUG [org.hibernate.loader.Loader] result row: EntityKey[usermanager.menu400.entities.M4puser#CHCOPY]
      2007-02-06 16:40:29,575 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close ResultSet (open ResultSets: 1, globally: 1)
      2007-02-06 16:40:29,575 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.engine.TwoPhaseLoad] resolving associations for [usermanager.menu400.entities.M4puser#CHCOPY]
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.engine.TwoPhaseLoad] done materializing entity [usermanager.menu400.entities.M4puser#CHCOPY]
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.engine.StatefulPersistenceContext] initializing non-lazy collections
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.loader.Loader] done entity load
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] processing flush-time cascades
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] dirty checking collections
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.pretty.Printer] listing entities:
      2007-02-06 16:40:29,591 DEBUG [org.hibernate.pretty.Printer] usermanager.menu400.entities.M4puser{usrssn=0, usrsts=A, sysreq=Y, setlib= , mnulvl= , acctcd= , brkmql= , usrnpw= , setpgm= , menu=*NONE , usrnpd=0, userpw=CHCOPY , userpd=0, atnpgm= , user=CHCOPY, rsttrm=Y, rstcpb=Y, uname=Copy Shooter Profile - CH - Test, brktrm=Y, grpmnu=N, atnlib= , usrf3=Y, umnsty=F, brkmq= , hlplvl= }
      2007-02-06 16:40:29,606 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
      2007-02-06 16:40:29,606 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
      2007-02-06 16:40:29,606 DEBUG [org.hibernate.SQL] update menu400tdi.M4PUSER set umnsty=?, brkmq=?, atnpgm=?, mnulvl=?, grpmnu=?, setpgm=?, usrf3=?, sysreq=?, atnlib=?, rstcpb=?, rsttrm=?, menu=?, userpw=?, usrsts=?, uname=?, setlib=?, usrnpw=?, acctcd=?, brktrm=?, usrssn=?, hlplvl=?, usrnpd=?, brkmql=?, userpd=? where user=?
      2007-02-06 16:40:29,778 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
       at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
       at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
       at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:24)
       at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2338)
       at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2242)
       at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2542)
       at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
       at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
       at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
       at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
       at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
       at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
       at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
       at org.jboss.tm.TxManager.commit(TxManager.java:240)
       at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:131)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:263)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:58)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
       at $Proxy83.updateUser(Unknown Source)
       at usermanager.web.UserControllerBean.updateUserAction(UserControllerBean.java:60)
       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:585)
       at com.sun.el.parser.AstValue.invoke(AstValue.java:130)
       at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
       at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
       at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
       at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
       at javax.faces.component.UICommand.broadcast(UICommand.java:106)
       at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:94)
       at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:168)
       at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
       at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.renderCycle(BlockingServlet.java:438)
       at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.receiveUpdates(BlockingServlet.java:426)
       at com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:269)
       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: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.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.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
       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:595)
      2007-02-06 16:40:29,778 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
      2007-02-06 16:40:29,778 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 1, globally: 1) (open ResultSets: 0, globally: 0)]
      2007-02-06 16:40:29,778 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] mark transaction for rollback
      2007-02-06 16:40:29,825 DEBUG [org.jboss.ejb3.entity.ManagedEntityManagerFactory] ************** closing entity managersession **************
      
      


      Brian