title: Hibernate session problem for transactions
body: <p>I am new to hibernate and trying integrate hibernate with an existing spring based application.</p>
  
  <p>I configured session factory and transaction manager, transaction proxy template.</p>
  
  <p>I am also using Quartz scheduler in this application.</p>
  
  <p>When I run the application, I am getting the following exception.</p>
  
  <p>ERROR au.com.michaelpage.ctsgui.utils.OrganisationMergeProfileThread - Error while updating opportunity: <strong>Could not open Hibernate Session for transaction; nested exception is java.lang.IllegalStateException: Already value [org.springframework.jdbc.datasource.ConnectionHolder@9f6885] for key [weblogic.jdbc.common.internal.RmiDataSource@32b034] bound to thread [DefaultQuartzScheduler_Worker-0]</strong></p>
  
  <p>My hibernate session configuration:</p>
  
  <pre><code> &lt;bean id="sessionFactoryAU"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource"&gt;
          &lt;ref bean="profileAU" /&gt;
      &lt;/property&gt;
      &lt;property name="mappingResources"&gt;
          &lt;list&gt;
              &lt;value&gt;
                  /au/com/michaelpage/ctsgui/hibernate/dao/mappings/Opportunity.hbm.xml
              &lt;/value&gt;
              &lt;value&gt;
                  /au/com/michaelpage/ctsgui/hibernate/dao/mappings/Position.hbm.xml
              &lt;/value&gt;
              &lt;value&gt;
                  /au/com/michaelpage/ctsgui/hibernate/dao/mappings/EventRole.hbm.xml
              &lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;!-- Database Settings --&gt;
              &lt;prop key="hibernate.dialect"&gt;
                  org.hibernate.dialect.SybaseDialect
              &lt;/prop&gt;
              &lt;prop key="hibernate.query.factory_class"&gt;
                  org.hibernate.hql.ast.ASTQueryTranslatorFactory
              &lt;/prop&gt;
  
              &lt;!-- Cache settings --&gt;
              &lt;prop key="hibernate.cache.provider_class"&gt;
                  org.hibernate.cache.EhCacheProvider
              &lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Transaction manager for a Hibernate SessionFactory --&gt;
  &lt;bean id="txManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory"&gt;
          &lt;ref bean="sessionFactoryAU" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Transaction template for Managers --&gt;
  &lt;bean id="txProxyTemplateHibernateProfileAU" abstract="true"
      class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;
      &lt;property name="transactionManager"&gt;
          &lt;ref bean="txManager" /&gt;
      &lt;/property&gt;
      &lt;property name="transactionAttributes"&gt;
          &lt;props&gt;
              &lt;prop key="create*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
              &lt;prop key="save*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
              &lt;prop key="update*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
              &lt;prop key="delete*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
              &lt;prop key="remove*"&gt;PROPAGATION_REQUIRED&lt;/prop&gt;
              &lt;prop key="get*"&gt;PROPAGATION_SUPPORTS&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt; 
  
  &lt;bean id="organisationMergeProfileMgrAU"
      parent="txProxyTemplateHibernateProfileAU"&gt;
      &lt;property name="target"&gt;
          &lt;bean
              class="au.com.michaelpage.ctsgui.mgr.profile.OrganisationMergeProfileMgrImpl"&gt;
              &lt;property name="commonProfileDao"&gt;
                  &lt;ref bean="commonProfileDaoAU" /&gt;
              &lt;/property&gt;
              &lt;property name="organisationMergeProfileDao"&gt;
                  &lt;ref bean="organisationMergeDaoAU" /&gt;
              &lt;/property&gt;
              &lt;property name="hibernateOrganisationDAO"&gt;
                  &lt;ref bean="hibernateOrganisationDAOAU" /&gt;
              &lt;/property&gt;
              &lt;property name="hibernateOpportunityDAO"&gt;
                  &lt;ref bean="hibernateOpportunityDAOAU" /&gt;
              &lt;/property&gt;
              &lt;property name="hibernatePositionDAO"&gt;
                  &lt;ref bean="hibernatePositionDAOAU" /&gt;
              &lt;/property&gt;
              &lt;property name="hibernateEventRoleDAO"&gt;
                  &lt;ref bean="hibernateEventRoleDAOAU" /&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <hr>
  
  <p>My Quartz scheduler configuration:</p>
  
  <p>
          
          </p>
  
  <pre><code>&lt;bean id="organisationMergeJobDetail"
      class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"&gt;
      &lt;property name="targetObject" ref="organisationMergeJob" /&gt;
      &lt;property name="targetMethod" value="execute" /&gt;
      &lt;property name="concurrent" value="false" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="organisationMergeProfileRegularCheckerTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"&gt;
      &lt;property name="jobDetail" ref="organisationMergeJobDetail" /&gt;
      &lt;property name="repeatInterval"&gt;
          &lt;util:constant static-field="au.com.michaelpage.ctsgui.common.Constants.CHECK_FREQUENCY" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Here is the bean definition for 'organisationMergeJob' </p>
  
  <pre><code>&lt;bean id="organisationMergeJob" class="au.com.michaelpage.ctsgui.utils.OrganisationMergeProfileThread"&gt; 
     &lt;property name="organisationMergeMgr" ref="organisationMergeMgr"/&gt; 
  &lt;/bean&gt;
  
  &lt;bean id="organisationMergeMgr" class="au.com.michaelpage.ctsgui.mgr.OrganisationMergeMgrImpl"&gt;  
      &lt;property name="organisationMergeDao" ref="organisationMergeDao"/&gt;   
  &lt;/bean&gt;
  </code></pre>
  
  <p>Any help to solve this?</p>
  
  <p>Thank you in advance.</p>
  
  <hr>
  
  <p>Hi skaffman,</p>
  
  <p>Here is the stack trace of the error:</p>
  
  <pre><code> Could not open Hibernate Session for transaction; nested exception is java.lang.IllegalStateException: Already value [org.springframework.jdbc.datasource.ConnectionHolder@5f2fb8] for key [weblogic.jdbc.common.internal.RmiDataSource@326b7b] bound to thread [DefaultQuartzScheduler_Worker-3]
  Caused by: java.lang.IllegalStateException: Already value [org.springframework.jdbc.datasource.ConnectionHolder@5f2fb8] for key [weblogic.jdbc.common.internal.RmiDataSource@326b7b] bound to thread [DefaultQuartzScheduler_Worker-3]
      at org.springframework.transaction.support.TransactionSynchronizationManager.bindResource(TransactionSynchronizationManager.java:163)
      at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:526)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:350)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:262)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      at $Proxy73.updateEventRole(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      at $Proxy73.updateEventRole(Unknown Source)
      at au.com.michaelpage.ctsgui.utils.OrganisationMergeProfileThread.execute(OrganisationMergeProfileThread.java:100)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:283)
      at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:272)
      at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
      at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
  </code></pre>
  
  <p>Thank you.</p>
  
  <p>Here is the bean definition for 'organisationMergeMgr'</p>
  
  <pre><code>&lt;bean id="organisationMergeMgr" 
     class="au.com.michaelpage.ctsgui.mgr.OrganisationMergeMgrImpl"&gt;
     &lt;property name="organisationMergeDao" ref="organisationMergeDao"/&gt;
  &lt;/bean&gt;
  </code></pre>