views:

513

answers:

1

Hi all,

I am new to hibernate and trying integrate hibernate with an existing spring based application.

I configured session factory and transaction manager, transaction proxy template.

I am also using Quartz scheduler in this application.

When I run the application, I am getting the following exception.

ERROR au.com.michaelpage.ctsgui.utils.OrganisationMergeProfileThread - Error while updating opportunity: 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]

My hibernate session configuration:

 <bean id="sessionFactoryAU"
 class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 <property name="dataSource">
  <ref bean="profileAU" />
 </property>
 <property name="mappingResources">
  <list>
   <value>
    /au/com/michaelpage/ctsgui/hibernate/dao/mappings/Opportunity.hbm.xml
   </value>
   <value>
    /au/com/michaelpage/ctsgui/hibernate/dao/mappings/Position.hbm.xml
   </value>
   <value>
    /au/com/michaelpage/ctsgui/hibernate/dao/mappings/EventRole.hbm.xml
   </value>
  </list>
 </property>
 <property name="hibernateProperties">
  <props>
   <!-- Database Settings -->
   <prop key="hibernate.dialect">
    org.hibernate.dialect.SybaseDialect
   </prop>
   <prop key="hibernate.query.factory_class">
    org.hibernate.hql.ast.ASTQueryTranslatorFactory
   </prop>

   <!-- Cache settings -->
   <prop key="hibernate.cache.provider_class">
    org.hibernate.cache.EhCacheProvider
   </prop>
  </props>
 </property>
</bean>

<!-- Transaction manager for a Hibernate SessionFactory -->
<bean id="txManager"
 class="org.springframework.orm.hibernate3.HibernateTransactionManager">
 <property name="sessionFactory">
  <ref bean="sessionFactoryAU" />
 </property>
</bean>

<!-- Transaction template for Managers -->
<bean id="txProxyTemplateHibernateProfileAU" abstract="true"
 class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
 <property name="transactionManager">
  <ref bean="txManager" />
 </property>
 <property name="transactionAttributes">
  <props>
   <prop key="create*">PROPAGATION_REQUIRED</prop>
   <prop key="save*">PROPAGATION_REQUIRED</prop>
   <prop key="update*">PROPAGATION_REQUIRED</prop>
   <prop key="delete*">PROPAGATION_REQUIRED</prop>
   <prop key="remove*">PROPAGATION_REQUIRED</prop>
   <prop key="get*">PROPAGATION_SUPPORTS</prop>
  </props>
 </property>
</bean> 

<bean id="organisationMergeProfileMgrAU"
 parent="txProxyTemplateHibernateProfileAU">
 <property name="target">
  <bean
   class="au.com.michaelpage.ctsgui.mgr.profile.OrganisationMergeProfileMgrImpl">
   <property name="commonProfileDao">
    <ref bean="commonProfileDaoAU" />
   </property>
   <property name="organisationMergeProfileDao">
    <ref bean="organisationMergeDaoAU" />
   </property>
   <property name="hibernateOrganisationDAO">
    <ref bean="hibernateOrganisationDAOAU" />
   </property>
   <property name="hibernateOpportunityDAO">
    <ref bean="hibernateOpportunityDAOAU" />
   </property>
   <property name="hibernatePositionDAO">
    <ref bean="hibernatePositionDAOAU" />
   </property>
   <property name="hibernateEventRoleDAO">
    <ref bean="hibernateEventRoleDAOAU" />
   </property>
  </bean>
 </property>
</bean>


My Quartz scheduler configuration:

<bean id="organisationMergeJobDetail"
    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="organisationMergeJob" />
    <property name="targetMethod" value="execute" />
    <property name="concurrent" value="false" />
</bean>

<bean id="organisationMergeProfileRegularCheckerTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
    <property name="jobDetail" ref="organisationMergeJobDetail" />
    <property name="repeatInterval">
     <util:constant static-field="au.com.michaelpage.ctsgui.common.Constants.CHECK_FREQUENCY" />
    </property>
</bean>

Here is the bean definition for 'organisationMergeJob'

<bean id="organisationMergeJob" class="au.com.michaelpage.ctsgui.utils.OrganisationMergeProfileThread"> 
   <property name="organisationMergeMgr" ref="organisationMergeMgr"/> 
</bean>

<bean id="organisationMergeMgr" class="au.com.michaelpage.ctsgui.mgr.OrganisationMergeMgrImpl">  
    <property name="organisationMergeDao" ref="organisationMergeDao"/>   
</bean>

Any help to solve this?

Thank you in advance.


Hi skaffman,

Here is the stack trace of the error:

 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)

Thank you.

Here is the bean definition for 'organisationMergeMgr'

<bean id="organisationMergeMgr" 
   class="au.com.michaelpage.ctsgui.mgr.OrganisationMergeMgrImpl">
   <property name="organisationMergeDao" ref="organisationMergeDao"/>
</bean>
A: 

I'd like to see the code for the organisationMergeMgr but my guess would be that you have transactions staying open when they are not supposed because there is no explicit commit or rollback call that is made in all situations (even if you think it will always participate in a larger transaction these calls must be made to guarantee cleanup of transactional resources)

Ichorus