1 2 Previous Next 25 Replies Latest reply on Jan 8, 2009 5:51 AM by victor jitlin

    insert, update, delete using same page and input fields

    roman s Newbie

      hey guys!


      This is probably very easy, but I had a lot of troubles with a page which contains input fields for persons, and a list of all persons underneath it.


      I would like to use these fields to either:
      generate a new person if no person is selected in the list below or,
      edit the selected person,
      or
      delete the selected person.


      I ran into a lot of problems with my solution which looks like:


      Bean:


           @DataModel
           List<Athlet> athlets;
           
           @DataModelSelection
           Athlet athlet;
      
           @In (create = true)
           Athlet mathlet;
      
           public void delete() {
                if( !isSelected() )
                     return;
                
                logger.info( "removing athlet" + athlet );
                athletdao.deleteAthlet( athlet );
                loadAthletes();
                FacesMessages.instance().add( "Athlet " + athlet + "deleted" );
                athlet = null;
           }
      
           public void edit() {
                if( !isSelected() )
                     return;
                
                mathlet.setPending( athlet.isPending() );
                athlet = mathlet;
                
                logger.info( "editing athlet" + athlet );
                athletdao.editAthlet( athlet );
                loadAthletes();
                FacesMessages.instance().add( "Athlet " + athlet + "edited" );
           }
      
           public void store() {
                
                AthleticaChangeHelper.changeUpdateInfo( mathlet );
                mathlet.setPending(true);
                
                logger.info( "adding athlet" + mathlet );
                
                
                athletdao.addAthlet( mathlet );
                loadAthletes();
                FacesMessages.instance().add( "Athlet " + mathlet + "added" );
                mathlet = null;
           }
      
           public void clear() {
                logger.info("athlet cleared");
                athlet = null;
           }
      
           
           public Athlet getSelection() {
                return athlet;
           }
           
           @Factory (value="athlets")
           public void loadAthletes() {
                logger.info("loading athletes");
                athlets = complexathletdao.findAthlet( searchstring );
           }
      
           private boolean isSelected() {
                return athlet != null;
           }
      
           public void setSelection() {
                mathlet = athlet;
           }



      mathlet has event scope, and is basically used to get the data from the fields to the bean.


      The xhtml is straight forward... the input fields are attached to mathlet, the corresponding buttons edit, delete, insert only get displayed if an athlet is (not) selected. Clear is used to reset the fields to blank (which is also not working)


      My problems are that:
      If I click the delete button I get an:


      javax.ejb.EJBTransactionRolledbackException: Removing a detached instance



      Exception


      Editing also doesn't work that well, since I allways get a validation exception.


      The only thing that works perfekt is inserting a new athlet.


      So I would like to know if I'm heading the right way with this solution, and am just getting  something wrong, or if this is just a bad way to do this kind of stuff...?


      I've spend a lot of time with this issue, so any help is appreciated!


      Greets


        • 1. Re: insert, update, delete using same page and input fields
          roman s Newbie

          Has nobody got some ideas? I'm realy stuck with this.


          A strange problem is the org.hibernate.validator.InvalidStateException which I get when I try to edit an athlet. The strang thing about it is, that I don't get any validation errors if I check the athlet with:



          ClassValidator<Athlet> personValidator = new ClassValidator<Athlet>(Athlet.class);
                    
                    InvalidValue[] ivs = personValidator.getInvalidValues(athlet);

          .


          I would realy appreciate some help!


          Greets

          • 2. Re: insert, update, delete using same page and input fields
            Daniel Hinojosa Master

            Well you may be having problems for a variety of reasons.
            1. Event scope is too small for DataModel and DataModelSelection
            2. We have no idea what athletDAO is since you didn't provide it for us to look at.  We don't know what scope it uses, what persistence mechanism you are using etc.

            • 3. Re: insert, update, delete using same page and input fields
              roman s Newbie

              Hey Daniel!


              I'm using SMPC in my DAOS..


              athletdao is a SLSB and just uses the basic hibernate stuff.. so edit and delete look like:



                      @In (value="#{entityManager}")
                      EntityManager em;
                      
                      @Logger
                      Log logger;
                      
                      public void deleteAthlet(Athlet athlet){
                              em.remove( athlet );
                              logger.debug( "Athlet " + athlet + "deleted.");
                      }
              
                      public void editAthlet(Athlet athlet){
                              em.merge( athlet );
                              logger.debug( "edited Athlet: " + athlet );
                      }



              What did you mean with Event scope is too small for DataModel and DataModelSelection??


              I'm using the event scope just for mathlet. mathlet  is attached to the input fields in the frontend...
              The reason for that is, that the values should be used to generate a new athlet (if none is selected) or use  the values to edit an athlet (for the selected one).
              I can't attach the input fields to the datamodelselection because it would be resolved to null, if no athlete is selected.


              Thanks for the help!
              Greets

              • 4. Re: insert, update, delete using same page and input fields
                João Bosco Monteiro Newbie

                Small scope means that your DataModel and DataModelSelection are not the same as previous in the last page interaction. This DataModelSelection object doesn't belong to current persistence context and it is the reason of detached instance exception.


                For testing this, higher you scope to Conversation and it should work fine.


                If you have to maintain for any reason the Event scope, you will have to merge DataModelSelection object before removing it.



                • 5. Re: insert, update, delete using same page and input fields
                  roman s Newbie

                  Thanks for the reply, but changing the scope didn't change anything. I still have the problem with the detached instance.


                  I don't understand why you think the event scope causes problems.. this is only used to get the data from/to the input fields.. the actual instances in the datamodel are bound to the page scope.. and  I only use the datamodelselection to remove/edit entities...

                  • 6. Re: insert, update, delete using same page and input fields
                    Daniel Hinojosa Master

                    Make sure that your DAO and your bean that you first posted is on the higher scope (CONVERSATION in this case), and make sure that if you do use conversation that you somehow start the conversation, and that you keep that conversation alive. 


                    Another option is maybe for testing purposes increase the DAO and bean to SESSION for a while so you don't have to concern yourself with Starting, Joining, and Stopping the conversation.  After you analyze the issue, you can put it to conversation or any other scope. 
                    The problem is that typically when you encounter


                    javax.ejb.EJBTransactionRolledbackException: Removing a detached instance
                    


                    The SMPC session shadow that is supposed to follow your entity is closed. You are in possession of an entity with has no home. Effectively you are removing an entity without the SMPC to do it because it went out of scope.




                    • 7. Re: insert, update, delete using same page and input fields
                      roman s Newbie

                      Hey again!


                      Nice idea, since the DAO's are holding the entitymanager, but actually it didn't work out.


                      I'm a bit frustrated since this shouldn't be so complex....


                      Anyway.. I still get the same error.


                      I thought I might put a bit more code in here so you can check things out:


                      bean:


                      @Name ("athlet")
                      @Roles({@Role (name="mathlet", scope=ScopeType.EVENT),...})               
                      public class Athlet { ... }



                      xhtml:



                      <s:decorate template="layout/edit.xhtml">
                           <ui:define name="label">name:</ui:define>
                           <h:inputText id="athlet_name" value="#{mathlet.name}" required="true"/>
                      </s:decorate>
                      ....
                      
                      <s:decorate template="layout/edit_button.xhtml" rendered="#{manageathlet.selection != null}">
                           <ajax:commandButton id="delete" action="#{manageathlet.delete}" value="delete" styleClass="buttons"/>
                      </s:decorate>
                      
                      <s:decorate template="layout/edit_button.xhtml" rendered="#{manageathlet.selection != null}">
                           <ajax:commandButton id="edit" action="#{manageathlet.edit}" value="edit" styleClass="buttons" reRender="inputfields, searchResults"/>
                      </s:decorate>
                      
                      ...
                      
                      <rich:dataTable id="athlet_table" value="#{athlets}" var="a" rendered="#{athlets.rowCount>0}">
                           ...
                           <rich:column>
                                <h:form>
                                     <h:commandButton value="Athlet Ausw&#228;hlen" action="#{manageathlet.setSelection}"/>
                                </h:form>
                           </rich:column>



                      action class (only relevant stuff):



                      @Name("manageathlet")
                      @Restrict("#{s:hasRole('admin')}")
                      @Scope(ScopeType.SESSION)
                      public class ManageAthlet implements IManageAthlet {
                      
                           
                           @DataModel
                           List<Athlet> athlets;
                           
                           @DataModelSelection
                           Athlet athlet;
                           
                           @In
                           IAthletDAO athletdao;
                      
                           @In (create = true)
                           @Out (required = false)
                           Athlet mathlet;
                      
                           ...
                      
                           public void delete() {
                                if( !isSelected() )
                                     return;
                                
                                logger.info( "removing athlet" + athlet );
                                athletdao.deleteAthlet( athlet );
                                loadAthletes();
                                FacesMessages.instance().add( "Athlet " + athlet + "deleted" );
                                athlet = null;
                           }
                      
                           public void edit() {
                                if( !isSelected() )
                                     return;
                                
                                athlet.setAdress( mathlet.getAdress() );
                                athlet.setBirthdate( mathlet.getBirthdate() );
                                athlet.setCity( mathlet.getCity() );
                                athlet.setClub( mathlet.getClub() );
                                athlet.setCountrycode( mathlet.getCountrycode() );
                                athlet.setFemale( mathlet.getFemale() );
                                athlet.setName( mathlet.getName() );
                                athlet.setPending( true );
                                athlet.setPhone( mathlet.getPhone() );
                                athlet.setProvince( mathlet.getProvince() );
                                athlet.setSurname( mathlet.getSurname() );
                                
                                AthleticaChangeHelper.changeUpdateInfo( athlet );
                                
                                ClassValidator<Athlet> personValidator = new ClassValidator<Athlet>(Athlet.class);
                                
                                InvalidValue[] ivs = personValidator.getInvalidValues(athlet);
                                
                                for( InvalidValue iv : ivs ) {
                                     logger.info("bean: " + iv.getBean());
                                     logger.info("rootbean: "+iv.getRootBean());
                                     logger.info("bean class: "+iv.getBeanClass());
                                     logger.info("message: "+iv.getMessage());
                                     logger.info("property name: "+iv.getPropertyName());
                                     logger.info("property path: "+iv.getPropertyPath());
                                     logger.info("value: "+iv.getValue());
                                }
                                
                                logger.info( "editing athlet" + athlet );
                                athletdao.editAthlet( athlet );
                                //loadAthletes();
                                //FacesMessages.instance().add( "Athlet " + athlet + "edited" );
                           }
                      
                           public void clear() {
                                logger.info("athlet cleared");
                                athlet = null;
                                mathlet = null;
                           }
                      
                           public Athlet getSelection() {
                                return athlet;
                           }
                           
                           @Factory (value="athlets")
                           public void loadAthletes() {
                                logger.info("loading athletes");
                                athlets = complexathletdao.findAthlet( searchstring );
                           }
                      
                           public void setSelection() {
                                mathlet = athlet;
                           }
                      




                      So as you can see athletes get loaded in the data selection.


                      if an athlet is selected, mathlet is outjected and gets displayed in the formes.


                      the actual operations on the dao are always done with the athlete from the datamodelselection.
                      ...
                      And as I said in the first post.. edit also doesn't work because he says that the athlet is not valid, though if I check it (as I do in the edit method), everything seems fine.


                      I hope you can help me out with this!


                      Greets

                      • 8. Re: insert, update, delete using same page and input fields
                        Guillaume Jeudy Master

                        I think SMPC is using conversation scope for the entityManager by default. Can you tell us how you declared the scope of your entityManager? I have trouble believing you get the same error if it were Session scope.

                        • 9. Re: insert, update, delete using same page and input fields
                          Cloves Almeida Newbie

                          It's really easy to get lost on entityManager scopes, specially in the beginning.


                          Whenever you run into such detached entity problems, try to check whether the EntityManager instance contains the entity you're trying to manipulate.


                          In your AthleteDAO, try:


                          public void delete(Athlete athlete) {
                              if (!entityManager.contains(athlete))
                                  athlete = entityManager.find(Athlete.class,athlete.getId());
                                  
                                  entityManager.delete(athlete);
                          }
                          

                          • 10. Re: insert, update, delete using same page and input fields
                            roman s Newbie

                            Even if I inject the entitymanager like:



                            @Name("athletdao")
                            @AutoCreate
                            @Scope(ScopeType.SESSION)
                            @Stateful
                            public class AthletDAO implements IAthletDAO {
                            
                                 @In (value="#{entityManager}", scope=ScopeType.SESSION)
                                 EntityManager em;



                            nothing changes....

                            • 11. Re: insert, update, delete using same page and input fields
                              roman s Newbie

                              Things are getting worst...


                              If I try to reload the athlet by the find methode I get an exception:


                              Caused by: java.lang.IllegalArgumentException: xxx.Athlet
                                   at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:191)
                                   at org.jboss.seam.persistence.EntityManagerProxy.find(EntityManagerProxy.java:85)
                                   at com.ase.grp4166.athletica.src.persistent.daos.AthletDAO.deleteAthlet(AthletDAO.java:41)
                                   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 org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                                   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                                   at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
                                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                                   at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
                                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                                   at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
                                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                                   at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
                                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                                   at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:26)
                                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                                   at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:27)
                                   at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                                   at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                                   at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
                                   at sun.reflect.GeneratedMethodAccessor123.invoke(Unknown Source)
                                   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                                   at java.lang.reflect.Method.invoke(Method.java:585)
                                   at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
                                   at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
                                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                                   at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
                                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                                   at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
                                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                                   at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                                   at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                                   at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
                                   ... 161 more
                              Caused by: java.lang.ClassCastException: xxx.Athlet
                                      at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:174)
                              


                              strack trace actually is much longer but this is the relevant stuff I think..


                              Since such basic stuff is not working, maybe there is some misconfiguration concerning the entitymanager (but I don't know what could be wrong in these three lines:


                              <persistence:managed-persistence-context name="entityManager"
                                     auto-create="true"
                                     persistence-unit-jndi-name="java:/myEntityManagerFactory"/>



                              Thanks for your concern!


                              Greets




                              • 12. Re: insert, update, delete using same page and input fields
                                Guillaume Jeudy Master

                                Have you tried explicitely setting the scope of your entityManager to session in the persistence:managed-persistence-context bit ?

                                • 13. Re: insert, update, delete using same page and input fields
                                  roman s Newbie

                                  hm.. this changes things a bit.. seems like the athlete now doesn't get detached, but I now get the following exception:



                                  15:17:38,640 INFO  [STDOUT] Hibernate: 
                                      delete 
                                      from
                                          Athlets 
                                      where
                                          id=?
                                  15:17:38,640 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
                                  15:17:38,640 ERROR [JDBCExceptionReporter] failed batch
                                  15:17:38,640 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
                                  org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
                                       at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
                                       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
                                       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
                                       at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
                                       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
                                       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:146)
                                       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 com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
                                       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
                                       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
                                       at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
                                       at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
                                       at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
                                       at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
                                       at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
                                       at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
                                       at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:603)
                                       at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:341)
                                       at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:241)
                                       at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:192)
                                       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
                                       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
                                       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
                                       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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                       at org.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:42)
                                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
                                       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:154)
                                       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:260)
                                       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:366)
                                       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:493)
                                       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
                                       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.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:179)
                                       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:595)
                                  Caused by: java.sql.BatchUpdateException: failed batch
                                       at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
                                       at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
                                       at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:519)
                                       at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
                                       at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
                                       ... 64 more
                                  15:17:38,640 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@16f76a8
                                  javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
                                       at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
                                       at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:524)
                                       at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
                                       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:247)
                                       at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
                                       at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
                                       at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1389)
                                       at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
                                       at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
                                       at org.jboss.tm.usertx.client.ServerVMClientUserTransaction.commit(ServerVMClientUserTransaction.java:140)
                                       at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
                                       at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:603)
                                       at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:341)
                                       at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:241)
                                       at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:192)
                                       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
                                       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
                                       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
                                       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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                       at org.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:42)
                                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                                       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
                                       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:154)
                                       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:260)
                                       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:366)
                                       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:493)
                                       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
                                       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.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:179)
                                       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:595)
                                  Caused by: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
                                       at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
                                       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
                                       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
                                       at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
                                       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
                                       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:146)
                                       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)
                                       ... 57 more


                                  • 14. Re: insert, update, delete using same page and input fields
                                    Guillaume Jeudy Master

                                    Have you provided the full exception stack? It's hard to tell exactly why you are getting the exception.


                                    In any case, I dont recommend you use entityManager in session scope, it is meant to be used in a conversation scope. I asked you add put it this way just to confirm it is a scoping problem.


                                    I strongly recommend you read up on Seam scopes. By default a conversation lasts only a full request cycle. You need to use conversation management tags/attributes/annotations to promote your implicit conversation to a long-running conversation that can span multiple requests.


                                    Since the SMPC(read EntityManager) scope is conversation by default you will naturally have all loaded entities in a managed state for the duration of the conversation (no Detached exceptions should occur).


                                    Alternatively you can always troubleshoot the workaround approach that Cloves proposed. Basically entityManager.contains() will tell you if your entity is in a managed state. Which should be the case if you loaded the entity inside a long-running conversation.


                                    1 2 Previous Next