我是hibernate的新手,并尝试将hibernate与现有的基于spring的应用程序集成。
我配置了会话工厂和事务管理器,事务代理模板。
我也在这个应用程序中使用Quartz调度程序。
当我运行应用程序时,我收到以下异常。
错误au.com.michaelpage.ctsgui.utils.OrganisationMergeProfileThread - 更新商机时出错:无法打开Hibernate会话进行交易;嵌套异常是java.lang.IllegalStateException:已经绑定到线程[defaultQuartzScheduler_Worker-0]的密钥[weblogic.jdbc.common.internal.RmiDataSource@32b034]的值[org.springframework.jdbc.datasource.ConnectionHolder@9f6885]
我的hibernate会话配置:
<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>
我的Quartz调度程序配置:
<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>
这是'organisationMergeJob'
的bean定义<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>
有任何帮助可以解决这个问题吗?
提前谢谢。
嗨skaffman,
以下是错误的堆栈跟踪:
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)
谢谢。
这是'organisationMergeMgr'
的bean定义<bean id="organisationMergeMgr"
class="au.com.michaelpage.ctsgui.mgr.OrganisationMergeMgrImpl">
<property name="organisationMergeDao" ref="organisationMergeDao"/>
</bean>
答案 0 :(得分:0)
我想看看organisationMergeMgr的代码,但是我的猜测是你没有假设交易保持打开,因为在所有情况下都没有明确的提交或回滚调用(即使你认为它将始终参与更大的事务,必须进行这些调用以保证事务资源的清理)