Note that there are some explanatory texts on larger screens.

plurals
  1. POelegantly handling stale database connections in Hibernate/Spring Transactions
    primarykey
    data
    text
    <p>i have a system that has been working fine in testing but now that i have moved them to the production servers and am ready to throw the switch, im having a problem.</p> <p>if the application sits idle for around 15 minutes, the DB connection in the spring transaction service drops. the first person that comes to the app after that happens is greeted with this</p> <pre><code>org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open connection org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596) 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.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) parity.persistence.DataAccess$$EnhancerByCGLIB$$921ef13.find(&lt;generated&gt;) parity.model.Configuration.getConfiguration(Configuration.java:84) parity.model.Configuration.getSetting(Configuration.java:46) parity.model.Configuration$$FastClassByCGLIB$$8355c3d0.invoke(&lt;generated&gt;) net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:617) parity.model.Configuration$$EnhancerByCGLIB$$5e96e8b9.getSetting(&lt;generated&gt;) parity.model.OnlineStatus.getSiteStatus(OnlineStatus.java:50) parity.action.site.SiteStatusInterceptor.intercept(SiteStatusInterceptor.java:16) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498) org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434) root cause </code></pre> <p>if you hit F5 on your browser, it reconnects and runs just fine. it looks like spring is doing something along the lines of the first request, going eek, i died, and in the process of dieing, reconnecting to the database. but im not sure.</p> <p>i have been searching for ways to solve this but it looks like unless i am using c3p0 or weblogic everyone is clueless. is there a way to fix this? here are my config files</p> <p>hibernate.cfg.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt; &lt;property name="hibernate.connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt; &lt;property name="connection.autocommit"&gt;false&lt;/property&gt; &lt;property name="show_sql"&gt;false&lt;/property&gt; &lt;property name="use_sql_comments"&gt;false&lt;/property&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre> <p>transaction-service.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;bean id="boardingSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="configLocations"&gt; &lt;list&gt; &lt;value&gt;classpath:hibernate/boarding-hibernate.cfg.xml&lt;/value&gt; &lt;value&gt;classpath:boarding-hibernate.cfg.xml&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="configurationClass"&gt; &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="boardingTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="boardingSessionFactory" /&gt; &lt;qualifier value="boarding" /&gt; &lt;/bean&gt; &lt;tx:advice id="boardingTxAdvice" transaction-manager="boardingTransactionManager"&gt; &lt;tx:attributes&gt; &lt;tx:method name="get*" read-only="true" /&gt; &lt;tx:method name="*" /&gt; &lt;/tx:attributes&gt; &lt;/tx:advice&gt; &lt;/beans&gt; </code></pre> <p>note, my hibernate uses 2 files, one in the API that handles global settings, and one in the app itself that has application specific settings. for purposes here, the global one is all that matters, i think.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload