8 Replies Latest reply on Jan 31, 2010 10:25 PM by Tony Brouwer

    Auto-commit with a4j:commandLink?

    Adrien FERIAL Newbie

      Hi!


      I have a problem and I don't understand what's going on! Just like there is a autocommit mode that is enabled and I don't get why and how.


      This is my code :


      I have a class that contains a Collection :


      @Entity
      public class ExperimentalGroup {
      ...
      @OneToMany(mappedBy = "experimentalGroup", cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE}, fetch = FetchType.LAZY)
          private Collection<RelSubjectExperimentalGroup> relSubjectExperimentalGroupList = new ArrayList<RelSubjectExperimentalGroup>(0);
      ...
      



      And the objects that are contained in the collection:


      @Entity
      @Table(name = "REL_SUBJECT_EXPERIMENTAL_GROUP")
      public class RelSubjectExperimentalGroup implements Serializable, Comparable<RelSubjectExperimentalGroup> {
      
          /** Subject */
          @ManyToOne
          @JoinColumn(name = "SUBJECT_ID", referencedColumnName = "SUBJECT_ID")
          private Subject subject;
      
          /** Experimental Group */
          @ManyToOne
          @JoinColumn(name = "EXPERIMENTAL_GROUP_ID", referencedColumnName = "EXPERIMENTAL_GROUP_ID")
          private ExperimentalGroup experimentalGroup;
      
          /** ID */
          @Id
          @GeneratedValue(strategy = IDENTITY)
          @Column(name = "REL_SUBJECT_EXPERIMENTAL_GROUP_ID")
          private long id;
      ...
      



      Then, to edit a ExperimentalGroup, I have this in my JSF page:



      <s:fragment>
         <s:decorate id="relSubjectExperimentalGroupListDecorate" template="../template/editWithoutPassedImg.xhtml">
            <ui:define name="label">#{msg['inrianeurotk.manageData.experimentalGroup.associated.subjects.associateNew']}:</ui:define>
                 <h:selectOneMenu id="selectSubject" tabindex="2" for="subject" value="#{experimentalGroupHome.currentSubject}">
                 <s:selectItems value="#{subjectList.completeResultList}" var="subject" label="#{subject.subjectIdentifier} - #{subject.name}" noSelectionLabel="#{msg['inrianeurotk.manageData.create.new.subject.choose']}" />
                 <s:convertEntity />
              </h:selectOneMenu>
         </s:decorate>
         <a4j:commandLink action="#{experimentalGroupHome.addSubject()}" id="createSubject" value="#{msg['inrianeurotk.manageData.experimentalGroup.subject.add']}" reRender="createExperimentalGroupForm">
         </a4j:commandLink>
      </s:fragment>



      In my JSF page, I can select a subject from the subject list and click on a add commandLink to add the subject to the collection of subjects of the current instance of ExeprimentalGroupHome.
      That is to say, I call the method addSubject() of ExperimentalGroupHome :


      @Name("experimentalGroupHome")
      @Scope(ScopeType.CONVERSATION)
      @Stateful
      public class ExperimentalGroupHome extends EntityHome<ExperimentalGroup> implements IExperimentalGroupHome {
      
        private Subject currentSubject;
      
        public void addSubject() {
              if (currentSubject != null) {
                  final RelSubjectExperimentalGroup relSubjectExperimentalGroup = new RelSubjectExperimentalGroup();
                  relSubjectExperimentalGroup.setSubject(currentSubject);
                  relSubjectExperimentalGroup.setExperimentalGroup(this.getInstance());
                  if (!this.getInstance().getRelSubjectExperimentalGroupList().contains(relSubjectExperimentalGroup)) {
                      this.getInstance().getRelSubjectExperimentalGroupList().add(relSubjectExperimentalGroup);
                      currentSubject.getRelSubjectExperimentalGroupList().add(relSubjectExperimentalGroup);
                  } 
              }
       }
      
      ...
      }



      What I want is to really add the subject when I click on the persist button of my JSF page. Thus, the persist method of ExperimentalGroupHome is then called.


      However, when I click on the Add button (call to the addSubject() method), I can see in the logs that a new RelSubjectExperimentalGroup has been created and has been given an id.


      I don't understand why the object RelSubjectExperimentalGroup is persisted! I don't call any method to do this.


      Any help would be very appreciated.


      Thanks in advance


      Adrien

        • 1. Re: Auto-commit with a4j:commandLink?
          Adrien FERIAL Newbie

          Well, I have a guess of what's happening. It has something to do with JSF lifecycles and that Seam Phase Listener.


          Here is the stacktrace when I want to add a subject to a new instance of ExperiementalGroup that is not yet in the database:



          10:49:17,488 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@3fec2f
          java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.inria.neurotk.core.model.RelSubjectExperimentalGroup.experimentalGroup -> org.inria.neurotk.core.model.ExperimentalGroup
               at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:627)
               at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:525)
               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.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:150)
               at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
               at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:379)
               at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:506)
               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.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.inria.neurotk.core.model.RelSubjectExperimentalGroup.experimentalGroup -> org.inria.neurotk.core.model.ExperimentalGroup
               at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:353)
               at org.hibernate.engine.Cascade.cascade(Cascade.java:139)
               at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:431)
               at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
               at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
               at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
               at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
               at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
               at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
               at org.hibernate.impl.SessionImpl.firePersistOnFlush(SessionImpl.java:644)
               at org.hibernate.impl.SessionImpl.persistOnFlush(SessionImpl.java:636)
               at org.hibernate.engine.CascadingAction$9.cascade(CascadingAction.java:323)
               at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
               at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
               at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
               at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
               at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
               at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
               at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
               at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
               at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
               at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
               at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
               at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
               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:516)
               ... 55 more
          10:49:17,488 ERROR [SeamPhaseListener] uncaught exception
          java.lang.IllegalStateException: Could not commit transaction
               at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:613)
               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.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:150)
               at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
               at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:379)
               at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:506)
               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: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
               at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1401)
               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)
               ... 45 more
          Caused by: java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.inria.neurotk.core.model.RelSubjectExperimentalGroup.experimentalGroup -> org.inria.neurotk.core.model.ExperimentalGroup
               at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:627)
               at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:525)
               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)
               ... 50 more
          Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.inria.neurotk.core.model.RelSubjectExperimentalGroup.experimentalGroup -> org.inria.neurotk.core.model.ExperimentalGroup
               at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:353)
               at org.hibernate.engine.Cascade.cascade(Cascade.java:139)
               at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:431)
               at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
               at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
               at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
               at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
               at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
               at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
               at org.hibernate.impl.SessionImpl.firePersistOnFlush(SessionImpl.java:644)
               at org.hibernate.impl.SessionImpl.persistOnFlush(SessionImpl.java:636)
               at org.hibernate.engine.CascadingAction$9.cascade(CascadingAction.java:323)
               at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
               at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
               at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
               at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
               at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
               at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
               at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
               at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
               at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
               at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
               at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
               at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
               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:516)
               ... 55 more


          • 2. Re: Auto-commit with a4j:commandLink?
            Adrien FERIAL Newbie

            How can I ask Seam not to try to commit the transaction?

            • 3. Re: Auto-commit with a4j:commandLink?
              Damian Harvey Apprentice

              You are adding the relSubjectExperimentalGroup to the currentSubject and you probably have this relationship set up to Cascade.PERSIST. When the method boundary is hit this cascade is fired.


              Cheers,


              Damian.

              • 4. Re: Auto-commit with a4j:commandLink?
                Adrien FERIAL Newbie

                I got it work by annotating the addSubject() method with :


                @Begin(flushMode = FlushModeType.MANUAL, join = true)



                Doy you think it is the right way to do it?

                • 5. Re: Auto-commit with a4j:commandLink?
                  Adrien FERIAL Newbie

                  Damian Harvey wrote on Sep 09, 2008 10:54:


                  You are adding the relSubjectExperimentalGroup to the currentSubject and you probably have this relationship set up to Cascade.PERSIST. When the method boundary is hit this cascade is fired.

                  Cheers,

                  Damian.


                  Damian,


                  Indeed, I have this in my Subject class :



                  OneToMany(cascade = CascadeType.ALL, mappedBy = "subject")
                  private List<RelSubjectExperimentalGroup> relSubjectExperimentalGroupList = new ArrayList<RelSubjectExperimentalGroup>(0);




                  However, I thought that the Cascade action (Cascade.PERSIST) is hit only when I ask explicitly to persist a Subject and not at the method boundary. Am I wrong?

                  • 6. Re: Auto-commit with a4j:commandLink?
                    Stefano Travelli Newbie

                    I also experienced this behavior with ajax4jsf and conversational components.


                    I think setting FlushMode.MANUAL for conversation is the correct solution and it's obvious if you think about it.


                    What you want is not to avoid Seam to commit the transaction but to avoid the EntityManager to flush when the transaction is going to commit, because the conversation spans several transaction, one for each ajax4jsf invoke.
                    Of course, at one point you need to manually flush the entity manager.


                    I use to set manual flush mode in .page.xml where the conversation begin.

                    • 7. Re: Auto-commit with a4j:commandLink?
                      Adrien FERIAL Newbie

                      Stefano Travelli wrote on Sep 09, 2008 12:21:


                      I also experienced this behavior with ajax4jsf and conversational components.

                      I think setting FlushMode.MANUAL for conversation is the correct solution and it's obvious if you think about it.

                      What you want is not to avoid Seam to commit the transaction but to avoid the EntityManager to flush when the transaction is going to commit, because the conversation spans several transaction, one for each ajax4jsf invoke.
                      Of course, at one point you need to manually flush the entity manager.

                      I use to set manual flush mode in .page.xml where the conversation begin.



                      That worked for me. Thanks a lot.

                      • 8. Re: Auto-commit with a4j:commandLink?
                        Tony Brouwer Newbie

                        Adrien,


                        I had much the same problem as you described. Putting FlushModel.MANUAL in the xxx.page.xml file is not enough:



                           <begin-conversation join="true" flush-mode="MANUAL"/>
                        



                        Only after annotating the ajax method like so did the update not get flushed:



                           @Begin(flushMode = FlushModeType.MANUAL, join=true )
                           public void releaseDogs() {
                               //Update some hibernate model objects ...
                           }
                        



                        Now my a4j button no longer causes entityManager to flush automatically:



                        <a4j:commandButton reRender="bigEditPanel" action="#{bigEditHome.releaseDogs}" value="Release The Dogs"/>
                        



                        I'm not sure why this is the case. Seems to me that simply having the flush mode page directive should suffice. But, without the @Begin annotation the modified model objects were getting flushed automatically at end of method.



                        Anyone have any further ideas? Methinks the additional annotation should be superfluous.