HibernateSystemException:没有Hibernate Session绑定到线程 [英] HibernateSystemException: No Hibernate Session bound to thread

查看:86
本文介绍了HibernateSystemException:没有Hibernate Session绑定到线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到 HibernateSystemException ,尽管我做了在不同论坛上提到的所有内容。 p>

 < 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆