4 Replies Latest reply on Dec 23, 2010 6:36 PM by wadhah jebri

    Exception : Could not commit transaction

    wadhah jebri Newbie

      Hello when i clic on the botton to register i have this exception Could not commit transaction
      this is my RegisterBean :



      package org.domain.registration.session;
      
      import java.util.List;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import javax.persistence.PersistenceContextType;
      
      import org.domain.registration.entity.User.User;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.faces.FacesMessages;
      import org.jboss.seam.international.StatusMessages;
      
      @Stateless
      @Name("Register")
      public class RegisterBean implements Register {
              @Logger
              private Log log;
      
              @In
              StatusMessages statusMessages;
              @In
              private User user;
              @PersistenceContext
              private EntityManager em;
      
              // public void register() {
              // // implement your business logic here
              // log.info("Register.register() action called");
              // statusMessages.add("register");
              // }
      
              public String register() {
                      // List<User> existing = em.createQuery(
                      // "select username from users where username=#{user.username}")
                      // .getResultList();
                      // if (existing.size() == 0) {
                      em.persist(user);
                      log.info("Registred new user #{user.username}");
                      return "/registered.xhtml";
                      // } else {
                      // FacesMessages.instance()
                      // .add("User #{user.username} already exists");
                      // return null;
              }
      
              // }
      
      }
      


      and this is my entity bean



      package org.domain.registration.entity.User;
      
      import java.io.Serializable;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Table;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Entity
      @Name("user")
      @Scope(ScopeType.SESSION)
      @Table(name = "users")
      public class User implements Serializable {
      
              private static final long serialVersionUID = 1L;
              private String name;
              private String username;
              private String password;
      
              public User(String name, String username, String password) {
                      this.name = name;
                      this.username = username;
                      this.password = password;
              }
      
              public User() {
              }
      
              @Id
              @NotNull
              @Length(min = 5, max = 15)
              public String getUsername() {
                      return username;
              }
      
              public void setUsername(String username) {
                      this.username = username;
              }
      
              @NotNull
              @Length(min = 5, max = 15)
              public String getPassword() {
                      return password;
              }
      
              public void setPassword(String password) {
                      this.password = password;
              }
      
              @Length(max = 20)
              @NotNull
              public String getName() {
                      return name;
              }
      
              public void setName(String name) {
                      this.name = name;
              }
      
      }
      


      and this is my register layout



      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:s="http://jboss.com/products/seam/taglib"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:rich="http://richfaces.org/rich"
              xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml">
      
              <ui:define name="body">
      
                      <rich:panel>
                              <f:facet name="header">register</f:facet>
      
                              <h:form id="RegisterForm">
                                      <s:validateAll>
                                              <h:panelGrid columns="2">
                        Username: <h:inputText id="username"
                                                              value="#{user.username}" required="true" />
                        Real Name: <h:inputText id="name" value="#{user.name}"
                                                              required="true" />
                        Password: <h:inputSecret id="password"
                                                              value="#{user.password}" required="true" />
                                              </h:panelGrid>
                                      </s:validateAll>
                                      <h:messages id="messages" />
                                      <h:commandButton id="register" value="register!"
                                              action="#{Register.register()}" />
                              </h:form>
                      </rich:panel>
      
              </ui:define>
      
      </ui:composition>
      


      here is the exception : 

      Exception during request processing:
      Caused by java.lang.IllegalStateException with message: "Could not commit transaction"


      plz i need a help


        • 1. Re: Exception : Could not commit transaction
          Tim Evers Master

          When asking for help with exceptions it is imperative that you provide the full stack trace. Without the entire stack trace it is almost impossible to know what the problem is.

          • 2. Re: Exception : Could not commit transaction
            wadhah jebri Newbie

            Ok excuse me i'm new in this forum.
            This is the first exception :

            Exception during request processing:
            Caused by javax.servlet.ServletException with message: "#{Register.register()}: javax.ejb.EJBTransactionRolledbackException: org.hibernate.hql.ast.QuerySyntaxException: users is not mapped [select username from users where username=:el1]"




            javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
            org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
            org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
            org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
            org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            java.lang.Thread.run(Unknown Source)

            This is the second exception :
            Caused by javax.faces.FacesException with message: "#{Register.register()}: javax.ejb.EJBTransactionRolledbackException: org.hibernate.hql.ast.QuerySyntaxException: users is not mapped [select username from users where username=:el1]"




            com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
            javax.faces.component.UICommand.broadcast(UICommand.java:387)
            org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
            org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
            org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
            org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
            com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
            com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
            com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
            javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
            org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
            org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
            org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
            org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
            java.lang.Thread.run(Unknown Source)







            • 3. Re: Exception : Could not commit transaction
              omid pourhadi Apprentice

              just some guess,


              try to change your interface name e.g IRegister


              try to change method call


              #{Register.register}



              • 4. Re: Exception : Could not commit transaction
                wadhah jebri Newbie

                I solved my problem in fact I created a project with the command prompt with seam genso the user table is mapped but when i added two input text username and password, i cliked on the register botton i had this exception :




                Exception during request processing
                Caused by javax.el.PropertyNotFoundException with message: "/register.xhtml @36,56 action="#{Register.register}": Target Unreachable, identifier 'Register' resolved to null"
                
                com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:70)
                javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                javax.faces.component.UICommand.broadcast(UICommand.java:387)
                javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
                javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
                com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:18)
                com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.renderCycle(ReceiveSendUpdates.java:122)
                com.icesoft.faces.webapp.http.core.ReceiveSendUpdates.service(ReceiveSendUpdates.java:73)
                com.icesoft.faces.webapp.http.core.RequestVerifier.service(RequestVerifier.java:28)
                com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:24)
                com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service(MainSessionBoundServlet.java:160)
                com.icesoft.faces.webapp.http.servlet.SessionDispatcher$1.service(SessionDispatcher.java:42)
                com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet.service(ThreadBlockingAdaptingServlet.java:19)
                com.icesoft.faces.webapp.http.servlet.EnvironmentAdaptingServlet.service(EnvironmentAdaptingServlet.java:63)
                com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:62)
                com.icesoft.faces.webapp.http.servlet.SessionVerifier.service(SessionVerifier.java:22)
                com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:23)
                com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:153)
                javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)
                org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
                org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                java.lang.Thread.run(Unknown Source)