Uploaded image for project: 'YesCart'
  1. YesCart
  2. YC-271 Persistence review
  3. YC-193

Could not open Hibernate Session for transaction after long inactivity

    Details

    • Type: Associated bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.0.0, 2.0.0
    • Fix Version/s: 1.0.0, 2.0.0
    • Component/s: sf server, sf web
    • Labels:
      None

      Description

      Hibernate chokes on closed session after long period of inactivity (say when server is left over night).
      Found this blog post that has some good suggestions: http://drglennn.blogspot.co.uk/2009/05/javasqlsqlexception-communication-link.html

      Seems like a good solution would be to specify:
      1. autoReconnect=true (either in url or property of data source bean)
      2. validationQuery=SELECT 1 (either in url or property of data source bean)

      Another solution here using context.xml http://www.codefin.net/2007/05/hibernate-and-mysql-connection-timeouts.html (in comments)
      <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
      driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/dbname"

      maxActive="30"
      maxIdle="5"
      validationQuery="SELECT 1"
      username="username"
      password="password"

      />

      Full stack trace:

      HTTP Status 500 -

      type Exception report

      message

      description The server encountered an internal error () that prevented it from fulfilling this request.

      exception

      org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC begin transaction failed:
      org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:440)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      sun.proxy.$Proxy191.getShopByDomainName(Unknown Source)
      org.yes.cart.web.application.ApplicationDirector.getShopByDomainName(ApplicationDirector.java:83)
      org.yes.cart.web.filter.ShopResolverFilter.doBefore(ShopResolverFilter.java:92)
      org.yes.cart.web.filter.AbstractFilter.doFilter(AbstractFilter.java:58)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
      org.yes.cart.web.filter.AbstractFilter.doFilter(AbstractFilter.java:62)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      root cause

      org.hibernate.TransactionException: JDBC begin transaction failed:
      org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:76)
      org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
      org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1396)
      org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:399)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      sun.proxy.$Proxy191.getShopByDomainName(Unknown Source)
      org.yes.cart.web.application.ApplicationDirector.getShopByDomainName(ApplicationDirector.java:83)
      org.yes.cart.web.filter.ShopResolverFilter.doBefore(ShopResolverFilter.java:92)
      org.yes.cart.web.filter.AbstractFilter.doFilter(AbstractFilter.java:58)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
      org.yes.cart.web.filter.AbstractFilter.doFilter(AbstractFilter.java:62)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      root cause

      com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

      The last packet successfully received from the server was 32,217,687 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
      sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      java.lang.reflect.Constructor.newInstance(Constructor.java:532)
      com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
      com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)
      com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3055)
      com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2941)
      com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3489)
      com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
      com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
      com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2562)
      com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4956)
      org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:371)
      org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:328)
      org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:72)
      org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
      org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1396)
      org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:399)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      sun.proxy.$Proxy191.getShopByDomainName(Unknown Source)
      org.yes.cart.web.application.ApplicationDirector.getShopByDomainName(ApplicationDirector.java:83)
      org.yes.cart.web.filter.ShopResolverFilter.doBefore(ShopResolverFilter.java:92)
      org.yes.cart.web.filter.AbstractFilter.doFilter(AbstractFilter.java:58)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
      org.yes.cart.web.filter.AbstractFilter.doFilter(AbstractFilter.java:62)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      root cause

      java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
      com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2502)
      com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2952)
      com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2941)
      com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3489)
      com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
      com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
      com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2562)
      com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4956)
      org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:371)
      org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:328)
      org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:72)
      org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
      org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1396)
      org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:399)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
      org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      sun.proxy.$Proxy191.getShopByDomainName(Unknown Source)
      org.yes.cart.web.application.ApplicationDirector.getShopByDomainName(ApplicationDirector.java:83)
      org.yes.cart.web.filter.ShopResolverFilter.doBefore(ShopResolverFilter.java:92)
      org.yes.cart.web.filter.AbstractFilter.doFilter(AbstractFilter.java:58)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
      org.yes.cart.web.filter.AbstractFilter.doFilter(AbstractFilter.java:62)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      note The full stack trace of the root cause is available in the Apache Tomcat/7.0.26 logs.

      Apache Tomcat/7.0.26

        Attachments

          Activity

            People

            • Assignee:
              denis.lozenko Denis Lozenko (Inactive)
              Reporter:
              denis Denis Pavlov
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: