3 Replies Latest reply on Dec 14, 2008 3:25 PM by david david

    seam database transaction connection

    david david Newbie
      I'm using seam, jpa, hibernate, mysql and tomcat6. the application works fine.
      however, when I use multithreaded httpclient to hit one url to do the performance test.

      I found one or a few same error below. it says something like max_user_connection. but the thing is my page never try to perform database actions.

      I think it might because the configuration. I'm using resource_local. I also listed my web.xml. I also tried to add jsf transactional phase listener but got a classnotfound exception.

      Could someone please shed some light? thanks.




      Dec 13, 2008 7:31:42 PM org.jboss.seam.contexts.Contexts startup
      INFO: starting up: org.jboss.seam.web.session
      Dec 13, 2008 7:31:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
      WARNING: SQL Error: 1203, SQLState: 42000
      Dec 13, 2008 7:31:42 PM org.hibernate.util.JDBCExceptionReporter logExceptions
      SEVERE: User amb already has more than 'max_user_connections' active connections
      Dec 13, 2008 7:31:42 PM org.jboss.seam.jsf.SeamPhaseListener beforePhase
      SEVERE: uncaught exception
      java.lang.IllegalStateException: Could not start transaction
              at org.jboss.seam.jsf.SeamPhaseListener.begin(SeamPhaseListener.java:592)
              at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsBeforePhase(SeamPhaseListener.java:323)
              at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:140)
              at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:114)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:222)
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
              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:154)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:260)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:366)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:493)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.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.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
              at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Cannot open connection
              at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
              at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:41)
              at org.jboss.seam.transaction.EntityTransaction.begin(EntityTransaction.java:82)
              at org.jboss.seam.jsf.SeamPhaseListener.begin(SeamPhaseListener.java:587)
              ... 34 more
      Caused by: org.hibernate.exception.SQLGrammarException: Cannot open connection
              at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
              at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
              at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
              at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
              at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
              at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
              at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
              at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
              at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:38)
              ... 36 more
      Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: User amb already has more than 'max_user_connections' active connections
              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
              at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
              at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
              at com.mysql.jdbc.Util.getInstance(Util.java:381)
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
              at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
              at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
              at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
              at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
              at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
              at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
              at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
              at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
              at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
              at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
              at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
              at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
              at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
              at java.sql.DriverManager.getConnection(DriverManager.java:582)
              at java.sql.DriverManager.getConnection(DriverManager.java:154)
              at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
              at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
              ... 41 more
      Dec 13, 2008 7:31:42 PM org.jboss.seam.contexts.Contexts startup
      INFO: starting up: org.jboss.seam.security.identity
      Dec 13, 2008 7:31:42 PM org.jboss.seam.contexts.Contexts startup
      INFO: starting up: org.jboss.seam.web.session
      Dec 13, 2008 7:31:42 PM org.jboss.seam.contexts.Contexts startup
      INFO: starting up: org.jboss.seam.security.identity
      Dec 13, 2008 7:31:42 PM org.jboss.seam.contexts.Contexts startup
      INFO: starting up: org.jboss.seam.web.session



      web.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.5"
               xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">     
         
          <!-- Seam -->
              
          <listener>             
            <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>       
          </listener>   

          <filter>
            <filter-name>Seam Filter</filter-name>
            <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
            <init-param>
              <param-name>createTempFiles</param-name>
              <param-value>true</param-value>
            </init-param>
            <init-param>
              <param-name>maxRequestSize</param-name>
              <param-value>100000</param-value>
            </init-param>
          </filter>

          <filter-mapping>
            <filter-name>Seam Filter</filter-name>
            <url-pattern>/*</url-pattern>
          </filter-mapping>
         
          <servlet>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
          </servlet>
        
          <servlet-mapping>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <url-pattern>/seam/resource/*</url-pattern>
          </servlet-mapping>    
         
          <!-- Faces Servlet -->
         
          <servlet>             
            <servlet-name>Faces Servlet</servlet-name>             
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>             
            <load-on-startup>1</load-on-startup>       
          </servlet>
         
          <servlet-mapping>             
            <servlet-name>Faces Servlet</servlet-name>             
            <url-pattern>*.seam</url-pattern>       
          </servlet-mapping>

           
          <!-- JSF parameters -->
         
          <context-param>       
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>       
            <param-value>.xhtml</param-value>   
          </context-param>
         
          <context-param>       
            <param-name>facelets.DEVELOPMENT</param-name>       
            <param-value>true</param-value>   
          </context-param> 
         
          <session-config>
              <session-timeout>10</session-timeout>
          </session-config>
      </web-app>

        • 1. Re: seam database transaction connection
          Ronald van Kuijk Apprentice

          Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: User amb already has more than 'maxuserconnections' active connections

          uhhmmm.... isn't the cause obvious? Little tuning required I think

          • 2. Re: seam database transaction connection
            Ronald van Kuijk Apprentice

            Ahhh... sorry, missed the



            but the thing is my page never try to perform database actions.

            Do you have an entitymanager configured for this application? If so try to remove it. May make a difference

            • 3. Re: seam database transaction connection
              david david Newbie
              for this page and backing bean, no transaction manager needed. for other pages/backing bean in the application, I listed my config below, i even tried remove C3P0 connection pool part.

              what bothers me most is why the database connections are opened here. does seam start a transaction for each page request, even for a simple html request? if so, does seam open database connection through hibernate when seam start the transaction?

              persistence.xml
              <?xml version="1.0" encoding="UTF-8"?>
              <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                   version="1.0">
                   <persistence-unit name="AMxxxxx"
                        transaction-type="RESOURCE_LOCAL">
                        <provider>org.hibernate.ejb.HibernatePersistence</provider>

                        <properties>
                             <property name="hibernate.connection.url"
                                  value="jdbc:mysql://xxxxx.com:3307/amb" />
                             <property name="hibernate.connection.driver_class"
                                  value="com.mysql.jdbc.Driver" />
                             <property name="hibernate.connection.password"
                                  value="xxxxxxx" />
                             <property name="hibernate.connection.username" value="amb" />
                          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

                             <!-- Use the C3P0 connection pool. -->
                             <property name="c3p0.min_size" value="3" />
                             <property name="c3p0.max_size" value="5" />
                             <property name="c3p0.timeout" value="1800" />

                             <property name="hibernate.show_sql" value="true" />
                             <property name="hibernate.cache.provider_class"
                                  value="org.hibernate.cache.HashtableCacheProvider" />
                             <property name="hibernate.jdbc.batch_size" value="20" />
                        </properties>
                   </persistence-unit>
              </persistence>

              components.xml

              <?xml version="1.0" encoding="UTF-8"?>
              <components xmlns="http://jboss.com/products/seam/components"
                          xmlns:core="http://jboss.com/products/seam/core"
                          xmlns:persistence="http://jboss.com/products/seam/persistence"
                          xmlns:transaction="http://jboss.com/products/seam/transaction"
                          xmlns:security="http://jboss.com/products/seam/security"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xsi:schemaLocation=
                              "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                               http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                               http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd
                               http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                               http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">

                  <core:manager conversation-timeout="120000"
                                concurrent-request-timeout="500"
                                conversation-id-parameter="cid"/>
                               
                               
                  <persistence:entity-manager-factory name="AMxxxx"/>
                 
                  <transaction:entity-transaction entity-manager="#{em}"/>
                  <persistence:managed-persistence-context name="em"
                                             auto-create="true"
                                  entity-manager-factory="#{AMxxxx}"/>
                                 
                  <security:identity authenticate-method="#{authenticator.authenticate}"/>
                  <event type="org.jboss.seam.security.notLoggedIn">
                       <action execute="#{redirect.captureCurrentView}" />
                  </event>
                  <event type="org.jboss.seam.security.postAuthenticate">
                       <action execute="#{redirect.returnToCapturedView}" />
                  </event>
              </components>