异常信息:No Hibernate Session bound to thread, and configuration does not allow creation of non-transact

来源:互联网 发布:c语言双向冒泡排序算法 编辑:程序博客网 时间:2024/05/29 17:58

异常信息的意思是:没有将hibernate的会话绑定到线程中,配置不允许创建非事务;

也就是:在业务代码中没有对事务进行处理;


如何进行处理呢?(这边是居于注解开发方式的)

只需在业务实现类中添加注解@Transactional,(@Transactional可以添加在类上,或者添加在方法上)

@Transactionalpublic class RoleServiceImpl implements RoleService {


在使用@Transactional的前提,需要在配置文件中进行相关的配置的

<!-- 配置事务管理 -->

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


阅读全文
0 0