HibernateSystemException:没有Hibernate Session绑定到线程 [英] HibernateSystemException: No Hibernate Session bound to thread
问题描述
< bean id =transactionManagerclass =org.springframework.jdbc.datasource.DataSourceTransactionManager>
< property name =dataSourceref =dataSource/>
< / bean>
我还将@Transactional注释放置在我的课程上方。
@Transactional
public class MyClassImpl
< bean id = transactionManager
class =org.springframework.jdbc.datasource.DataSourceTransactionManager>
< property name =dataSourceref =dataSource/>
< / bean>
您需要 org.springframework.orm.hibernate3.HibernateTransactionManager
,正如您在 13.3.3 Hibernate>声明式事务划分。
DataSourceTransactionManager
用于普通JDBC,而不用于Hibernate(请参阅 12.3.8 JDBC> DataSourceTransactionManager
)。
你也需要这一行:
< tx:注解驱动transaction-manager =transactionManager/>
I am getting HibernateSystemException although I did everything that is mentioned on different forums.
Here is a part of applicationContext.xml
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
I also placed @Transactional annotaion above my class.
@Transactional
public class MyClassImpl
A) this is the wrong transaction manager:
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
you need org.springframework.orm.hibernate3.HibernateTransactionManager
, as you can see in 13.3.3 Hibernate > Declarative transaction demarcation.
DataSourceTransactionManager
is for plain JDBC, not for Hibernate (see 12.3.8 JDBC > DataSourceTransactionManager
).
B) you need this line also:
<tx:annotation-driven transaction-manager="transactionManager" />
这篇关于HibernateSystemException:没有Hibernate Session绑定到线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!