No Hibernate Session bound to thread, and configuration does not allow

今天晚上挺悲催的,遇到了这个问题花费我很长时间,现在总结如下:

到这这种情况的发生有两种情况:

1,没有配置事物只要在Spring配置文件中添加如下代码:

    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>

然后在DAO程序前面加上@Transactional即可。
2,连接数据的配置是否正确,如果连接字符串不正确的话,就不能够创建SessionFactory,也就无从谈起事务了。

原文地址:https://www.cnblogs.com/toSeeMyDream/p/5539281.html