1 Reply Latest reply on Dec 15, 2009 5:12 PM by ter ron

    Getting a SQLException Closed Connection after a while (Tomcat)

    ter ron Newbie

      Hello,


      After uploading my Seam application to the server (Tomcat), everything works fine.
      But when I try the same application (e.g. the next day) I am getting a  Closed Connection SQLException. I can see that in the Catalina.out log.




      java.sql.SQLException: Closed Connection
           at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
           at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
           at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
           at oracle.jdbc.driver.PhysicalConnection.setAutoCommit(PhysicalConnection.java:1029)
           at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331)
           at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:317)
           at org.hibernate.transaction.JDBCTransaction.toggleAutoCommit(JDBCTransaction.java:194)
           at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:142)
           at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
           at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
           at org.jboss.seam.transaction.EntityTransaction.commit(EntityTransaction.java:110)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:613)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:604)
           at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:345)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:245)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
           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.render(LifecycleImpl.java:139)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
           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.BaseFilter.doFilter(BaseFilter.java:532)
           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.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.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)
      ...
      Dec 11, 2009 9:39:01 AM org.hibernate.transaction.JDBCTransaction commit
      SEVERE: JDBC commit failed
      java.sql.SQLException: Io exception: Connection timed out
           at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
           at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
           at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
           at oracle.jdbc.driver.T4CConnection.doCommit(T4CConnection.java:533)
           at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:1119)
           at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.commit(DelegatingConnection.java:301)
           at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.commit(PoolingDataSource.java:200)
           at org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:139)
           at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:115)
           at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
           at org.jboss.seam.transaction.EntityTransaction.commit(EntityTransaction.java:110)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:613)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:604)
           at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:345)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:245)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
           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.render(LifecycleImpl.java:139)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
           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)
      ...
      Dec 11, 2009 9:39:01 AM org.hibernate.util.JDBCExceptionReporter logExceptions
      WARNING: SQL Error: 0, SQLState: null
      Dec 11, 2009 9:39:01 AM org.hibernate.util.JDBCExceptionReporter logExceptions
      SEVERE: Already closed.
      Dec 11, 2009 9:39:01 AM org.jboss.seam.jsf.SeamPhaseListener afterPhase
      WARNING: uncaught exception, passing to exception handler
      java.lang.IllegalStateException: Could not commit transaction
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:625)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:604)
           at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPhase(SeamPhaseListener.java:345)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:245)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
           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.render(LifecycleImpl.java:139)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
           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)
      ...
      Caused by: javax.persistence.RollbackException: Error while commiting the transaction
           at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
           at org.jboss.seam.transaction.EntityTransaction.commit(EntityTransaction.java:110)
           at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:613)
           ... 58 more
      Caused by: org.hibernate.exception.GenericJDBCException: Cannot release connection
           at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
           at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
           at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
           at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
           at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:455)
           at org.hibernate.jdbc.ConnectionManager.aggressiveRelease(ConnectionManager.java:406)
           at org.hibernate.jdbc.ConnectionManager.afterTransaction(ConnectionManager.java:293)
           at org.hibernate.jdbc.JDBCContext.afterTransactionCompletion(JDBCContext.java:221)
           at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:127)
           at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
           ... 60 more
      Caused by: java.sql.SQLException: Already closed.
           at org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:84)
           at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:181)
           at org.hibernate.connection.DatasourceConnectionProvider.closeConnection(DatasourceConnectionProvider.java:74)
           at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:451)
           ... 65 more
      Dec 11, 2009 9:40:21 AM org.hibernate.util.JDBCExceptionReporter logExceptions
      WARNING: SQL Error: 0, SQLState: null
      Dec 11, 2009 9:40:21 AM org.hibernate.util.JDBCExceptionReporter logExceptions
      SEVERE: Already closed.
      Dec 11, 2009 9:40:21 AM org.jboss.seam.Component destroy
      WARNING: Exception calling component @Destroy method: em
      org.hibernate.exception.GenericJDBCException: Cannot release connection
           at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
           at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
           at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
           at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
           at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:455)
           at org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:385)
           at org.hibernate.jdbc.ConnectionManager.close(ConnectionManager.java:324)
           at org.hibernate.impl.SessionImpl.close(SessionImpl.java:298)
           at org.hibernate.ejb.EntityManagerImpl.close(EntityManagerImpl.java:86)
           at org.jboss.seam.persistence.EntityManagerProxy.close(EntityManagerProxy.java:36)
           at org.jboss.seam.persistence.ManagedPersistenceContext.close(ManagedPersistenceContext.java:224)


      Is this related to a wrong configuration in the server.xml or components.xml?


      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:web="http://jboss.com/products/seam/web"
                  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.1.xsd 
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd 
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
      
          <core:init debug="true"/>
      
          <core:manager conversation-timeout="120000" 
                        concurrent-request-timeout="500"
                        conversation-id-parameter="cid"/>
                        
          <transaction:entity-transaction entity-manager="#{em}"/>
                        
          <persistence:entity-manager-factory name="myWebDatabase"/>
          
          <persistence:managed-persistence-context name="em"
                                     auto-create="true" 
                          entity-manager-factory="#{myWebDatabase}"/>
                          
          <security:identity authenticate-method="#{authenticator.authenticate}"/>  
      
      </components>
      


      server.xml



      <?xml version="1.0" encoding="UTF-8"?>
        <Server port="8005" shutdown="SHUTDOWN">
      
        <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
        <Listener className="org.apache.catalina.core.JasperListener"/>
        <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
        <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
      
        <GlobalNamingResources>
          <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
                    name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
        </GlobalNamingResources>
        <Service name="Catalina">
          <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
          <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
          <Engine defaultHost="localhost" name="Catalina">
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
            <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
              <Context docBase="/dir1/apache-tomcat-6.0.18/webapps/App1" path="/App1" reloadable="true" source="org.eclipse.jst.jee.server:App1"/>
              <Context crossContext="true" debug="5" docBase="/dir1/apache-tomcat-6.0.18/webapps/app1Web" path="/app1Web" reloadable="true" source="org.eclipse.jst.jee.server:app1Web">
                <Resource auth="Container" driverClassName="oracle.jdbc.OracleDriver" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/app1WebDS" 
                          password="pssw" type="javax.sql.DataSource" url="jdbc:oracle:thin:@dbhost.com:1111:DBINST" username="usrn"/>
              </Context>
            </Host>
          </Engine>
        </Service>
      </Server>
      





      Thanks for any idea,
      Ter