5 Replies Latest reply on Nov 13, 2009 9:22 PM by sai burgula

    InvalidStateException caused by merge of EntityManager

    peter irmstadt Newbie

      Hi!


      I am working with a user entity bean and want to create a 'update password' form. So I looked how it is solved in the booking example, but instead of saving the EntityManagers merge method raises an InvalidStateException.


      Do you know what my mistake is?


      Thank you in advance!


      The entity bean:


      @Entity
      @Name("loginuser")
      public class LoginUser implements Serializable
      {
           @Override
           public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + ((login == null) ? 0 : login.hashCode());
                return result;
           }
      
           @Override
           public boolean equals(Object obj) {
                if (this == obj)
                     return true;
                if (obj == null)
                     return false;
                if (getClass() != obj.getClass())
                     return false;
                LoginUser other = (LoginUser) obj;
                if (login == null) {
                     if (other.login != null)
                          return false;
                } else if (!login.equals(other.login))
                     return false;
                return true;
           }
           private int id;
           private boolean isAdmin;
           private String login;
           private String password;
           private List<Domain> domains;
           
           @Id @GeneratedValue
           @Column(name = "intLoginUserID")
           public int getId() {
                return id;
           }
      
           public void setId(int id) {
                this.id = id;
           }
      
           @Column(name = "blnAdmin")
           public boolean getIsAdmin() {
                return isAdmin;
           }
      
           public void setIsAdmin(boolean isAdmin) {
                this.isAdmin = isAdmin;
           }
           
           public LoginUser(){}
           
           @Override
           public String toString()
           {
                return String.format("User: " + this.login);
           }
           
           @Column(name = "strLogin", length = 10)
           @NotNull
           @Max(10)
           public String getLogin() {
                return login;
           }
           public void setLogin(String login) {
                this.login = login;
           }
           
           @Column(name = "strPassword",length = 12)
           @NotNull
           @Length(min = 4, max = 12)
           public String getPassword() {
                return password;
           }
           public void setPassword(String password) {
                this.password = password;
           }
           
           @DataModel
           @ManyToMany(targetEntity=Domain.class)
           @JoinTable(name = "rtUserHasDomains",
                     joinColumns = @JoinColumn(name = "intLoginUserID", referencedColumnName = "intLoginUserID"),
                     inverseJoinColumns = @JoinColumn(name = "intDomainID", referencedColumnName = "intDomainID"))
           public List<Domain> getDomains() {
                return domains;
           }
           public void setDomains(List<Domain> domains) {
                this.domains = domains;
                }     
      }



      the password manager:


      @Stateful
      @Scope(ScopeType.EVENT)
      @Name("passwordManager")
      @Restrict("#{identity.loggedIn}")
      public class PasswordManager implements IPasswordManager
      {
           private String verify;
           @Logger private Log log;
           @In @Out private LoginUser user;
      
           @PersistenceContext
           private EntityManager em;
           
           public String getVerify() {
                return verify;
           }
      
           public void setVerify(String verify) {
                this.verify = verify;
           }
      
           public String action()
           {
                if (user.getPassword().equals(verify))
                {
                     log.info("updating password for user " + user.toString());
                     user = em.merge(user);
                     log.info("Password updated");
                }else{
                     //messages.add("Passwords do not match");
                     log.error("Passwords do not match");
                     revertUser();
                     verify = null;
                }
                
                return null;
           }
           
           private void revertUser()
           {
                user = em.find(LoginUser.class, user.getId());
           }
           
           @Remove @Destroy
           public void remove()
           {}     
      }



      and this is the output when I try to change the password:


      23:25:40,908 INFO  [PasswordManager] updating password for user User: testuser
      23:25:40,920 INFO  [PasswordManager] Password updated
      23:25:40,923 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@1486eef
      javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: org.test.mailmanage.entity.LoginUser
           at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:527)
           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:614)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:605)
           at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:343)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:243)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:194)
           at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
           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.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           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:177)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           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.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           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:182)
           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(Unknown Source)
      Caused by: org.hibernate.validator.InvalidStateException: validation failed for: org.test.mailmanage.entity.LoginUser
           at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:143)
           at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:172)
           at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
           at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
           at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
           at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
           at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
           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)
           ... 59 more
      23:25:40,932 WARN  [SeamPhaseListener] uncaught exception, passing to exception handler
      java.lang.IllegalStateException: Could not commit transaction
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:626)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:605)
           at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:343)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:243)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:194)
           at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
           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.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           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:177)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           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.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           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:182)
           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(Unknown Source)
      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:614)
           ... 49 more
      Caused by: javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: org.test.mailmanage.entity.LoginUser
           at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:527)
           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)
           ... 54 more
      Caused by: org.hibernate.validator.InvalidStateException: validation failed for: org.test.mailmanage.entity.LoginUser
           at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:143)
           at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:172)
           at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
           at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
           at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
           at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
           at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
           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)
           ... 59 more

        • 1. Re: InvalidStateException caused by merge of EntityManager
          Stuart Douglas Master

          The error is validation failed so I would say password is to short or to long, or login is to long.
          You should really be using hashed passwords anyway...

          • 2. Re: InvalidStateException caused by merge of EntityManager
            peter irmstadt Newbie

            I want to use hashed passwords when that web gets productive, but you are right!


            I tried to use a password that was definitely in the right range :(


            I tried to debug and stepped into it as well. The 'user' property is assigned correctly.


            I wonder why 'password updated' log is executed while the error is thrown during the merge..


            Any other ideas?

            • 3. Re: InvalidStateException caused by merge of EntityManager
              peter irmstadt Newbie

              I got me debug function to work again, so I took a deep look what's going on. It is very strange: Sometimes when I click on a delete button inside the datatable (see code below) a MailUser object is passed that has already been deleted before. That is why the NullPointerException is raised.


              This is the web page I am displaying the MailUsers on:


              <h:form>
                        <h:panelGrid columns="3">
                             <h:outputText value="Domainauswahl:" />
                             <h:selectOneMenu value="#{manager.domain}" required="true" >
                                  <s:selectItems var="dom" value="#{user.domains}" label="#{dom.name}" noSelectionLabel="Choose one"></s:selectItems>
                                  <s:convertEntity />
                             </h:selectOneMenu>
                             <h:commandButton action="#{manager.action}" value="OK"  type="submit"/>
                        </h:panelGrid>
                                  
                        <br/>
                        <h:outputText value="No Mailusers!"  rendered="#{empty manager.domain.mailuser}" />
                        <h:dataTable value="#{manager.domain.mailuser}"   var="_usr" rendered="#{not empty manager.domain.mailuser}" >
                        <h:column>
                        <f:facet name="header">Name</f:facet>
                        <h:outputText value="#{_usr.username}@#{manager.domain.name}" />
                        </h:column>
                        <h:column>
                        <h:commandButton action="#{manager.delete(_usr)}" value="Del" />
                        </h:column>
                        </h:dataTable>
                        </h:form>



              and this is the full manager bean code:


              @Stateful
              @Scope(ScopeType.EVENT)
              @Name("manager")
              public class Manager implements IManager 
              {
                   @In
                   private LoginUser user;
              
                   private MailUser mailuser = new MailUser();
                   
                   public MailUser getMailuser() {
                        return mailuser;
                   }
              
                   public void setMailuser(MailUser mailuser) {
                        this.mailuser = mailuser;
                   }
              
                   @In(required = false) @Out(required = false)
                   private Domain domain = null;
                   
                   @PersistenceContext
                   private EntityManager em;
                   
                   public Domain getDomain() {
                        if (domain != null)
                             return domain;
                        else
                             if (user.getDomains().size() > 0)
                                  return user.getDomains().get(0);
                             else
                                  return null;
                   }
              
                   public void setDomain(Domain domain) {
                        this.domain = domain;
                   }
              
                   
                   @Logger private Log log;
                   
                   @Remove @Destroy
                   public void destroy()
                   {}
                   
                   public String delete(MailUser objMailuser)
                   {
                        domain.getMailuser().remove(objMailuser);
                        objMailuser = (MailUser)em.find(MailUser.class, objMailuser.getId());
                        objMailuser.setDomain(null);
                        em.merge(objMailuser);
                        log.info("Deleting user: {0}", objMailuser.getUsername());
                        em.remove(objMailuser);
                        
                        return null;
                   }
                   
                   public String action()
                   {
                        log.info("Domain: {0}", (domain != null) ? domain.getName() : "none" ); 
                        return null;
                   }
              }



              I have a different site to create new MailUsers. When I create new Mail Users and then return to the display site (s.a.) then only the old users are shown. Even users I have deleted before are shown there. When I click on the 'OK' button (which was just a debug function for me before) the right values are displayed. Nevertheless the problem mentioned above still remains after that click. Some users can be deleted, some not. Especially the last user can't be deleted at all - an old user is passed then.


              I reduced the scope of the two entity beans (MailUser, Domain) as well as the manager to EVENT, but that doesn't change anything.


              Do you know where my mistake might be?


              Thank you so much in advance!

              • 4. Re: InvalidStateException caused by merge of EntityManager
                sai burgula Novice
                Hi Peter

                I am also encountering the same problem in updating an object. Please let me know what changes I can make to get it to work.

                In my case the update works for some objects, those that I had added into the DB, but for exisiting objects, I get the following stack trace.

                Invalid State Exception
                -----------------------

                javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: edu.cmu.heinz.hcis.entity.CourseOffering
                at
                org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:535) 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:1406)
                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:146)
                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.Phase.handleAfterPhase(Phase.java:175)
                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
                at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                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.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:177)
                at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
                at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
                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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                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:173)
                at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
                at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
                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:241)
                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:447)
                at java.lang.Thread.run(Unknown Source)
                Caused by: org.hibernate.validator.InvalidStateException: validation failed for: edu.cmu.heinz.hcis.entity.CourseOffering
                at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:148)
                at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:177)
                at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
                at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
                at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
                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:523)
                ... 56 more
                15:11:39,751 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.Phase.handleAfterPhase(Phase.java:175)
                at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
                at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                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.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:177)
                at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
                at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
                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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                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:173)
                at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
                at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
                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:241)
                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:447)
                at java.lang.Thread.run(Unknown Source)
                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:1418)
                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:146)
                at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
                at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:603)
                ... 46 more
                Caused by: javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: edu.cmu.heinz.hcis.entity.CourseOffering
                at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:535)
                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:1406)
                ... 51 more
                Caused by: org.hibernate.validator.InvalidStateException: validation failed for: edu.cmu.heinz.hcis.entity.CourseOffering
                at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:148)
                at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:177)
                at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
                at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
                at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
                at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
                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:523)
                --------------------------------------------------------------

                I noticed that you said use persist instead of merge.

                I even made that change but the exception does not seem to go away.


                I also noticed a strange behavior

                For objects that I had added and updated, it(Hibernate save) works fine.

                But for objects that are existing, I get a invalid state exception.

                I tried refreshing the DB and checking if the DB is able to access the object, and it does it successfully

                Please give me an insight into this.
                • 5. Re: InvalidStateException caused by merge of EntityManager
                  sai burgula Novice
                  Hi Stuart,

                  Hi Dean

                  I am also encountering the same problem in updating an object. Please let me know what changes I can make to get it to work.

                  In my case the update works for some objects, those that I had added into the DB, but for exisiting objects, I get the following stack trace.

                  Invalid State Exception
                  -----------------------

                  javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: edu.cmu.heinz.hcis.entity.CourseOffering
                  at
                  org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:535) 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:1406)
                  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:146)
                  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.Phase.handleAfterPhase(Phase.java:175)
                  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
                  at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                  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.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:177)
                  at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                  at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
                  at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
                  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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                  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:173)
                  at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
                  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                  at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
                  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:241)
                  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:447)
                  at java.lang.Thread.run(Unknown Source)
                  Caused by: org.hibernate.validator.InvalidStateException: validation failed for: edu.cmu.heinz.hcis.entity.CourseOffering
                  at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:148)
                  at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:177)
                  at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
                  at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
                  at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
                  at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
                  at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
                  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:523)
                  ... 56 more
                  15:11:39,751 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.Phase.handleAfterPhase(Phase.java:175)
                  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
                  at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                  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.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:177)
                  at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                  at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
                  at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
                  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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
                  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:173)
                  at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
                  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                  at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
                  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:241)
                  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:447)
                  at java.lang.Thread.run(Unknown Source)
                  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:1418)
                  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:146)
                  at org.jboss.seam.transaction.UTTransaction.commit(UTTransaction.java:52)
                  at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:603)
                  ... 46 more
                  Caused by: javax.persistence.PersistenceException: org.hibernate.validator.InvalidStateException: validation failed for: edu.cmu.heinz.hcis.entity.CourseOffering
                  at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:535)
                  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:1406)
                  ... 51 more
                  Caused by: org.hibernate.validator.InvalidStateException: validation failed for: edu.cmu.heinz.hcis.entity.CourseOffering
                  at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:148)
                  at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:177)
                  at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
                  at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
                  at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
                  at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
                  at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
                  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:523)
                  --------------------------------------------------------------

                  I noticed that you said use persist instead of merge.

                  I even made that change but the exception does not seem to go away.


                  I also noticed a strange behavior

                  For objects that I had added and updated, it(Hibernate save) works fine.

                  But for objects that are existing, I get a invalid state exception.

                  I tried refreshing the DB and checking if the DB is able to access the object, and it does it successfully

                  Please give me an insight into this.