我面臨的一個問題,我有一個方法,該方法是調用另一個方法在服務層如下:@Transaction問題:TransactionSynchronization.beforeCompletion拋出異常
@Transactional
@Override
public void method1(List<String> vals)
{
for (String value : vals){
method2(value);
}
}
@Transactional(propagation= Propagation.REQUIRED)
public void method2(String value)
{
//Hibernate Call 1
//Hibernate Call 2
}
我已經把Transactional註解方法2因爲它也可以從Controller中調用。
我的事務管理器看起來是這樣的:
<tx:annotation-driven transaction-manager="transactionManager"/>
<aop:aspectj-autoproxy/>
<!-- Transaction manager for hibernate -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
<property name="dataSource" ref="dataSource"></property>
</bean>
當控制器調用方法1這是給下面的錯誤,當我運行這段代碼:
11年12月22日18:4455410:ERROR [HTTP-8181-1] (.support.TransactionSynchronizationUtils:87) - TransactionSynchronization.beforeCompletion拋出異常 java.lang.IllegalStateException:用於密鑰 [org.hib No值[email protected]]結合到線程 [HTTP-8181-1在org.springframework.orm.hibernate3.SpringSessionSynchronization] 在org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:190) .beforeCompletion(SpringSessionSynchronization.java:187) 在org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCompletion(TransactionSynchronizationUtils.java:84) 在org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCompletion(AbstractPlatformTransactionManager.java:895) 在org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:693) at org.spri ngframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678) 在org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321) 在org.springframework.transaction.interceptor.TransactionInterceptor.invoke( TransactionInterceptor.java:116) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) 在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) 在$ Proxy31 .method1(Unknown Source)