Spring注解配置事务管理——问题

来源:互联网 发布:程序员个人评价 编辑:程序博客网 时间:2024/04/30 12:02

在上下文中配置:

<!-- 配置注解驱动的Spring MVC控制器编程模型。 --><bean id="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><tx:annotation-driven transaction-manager="transactionManager" />

注意:

1.如果配置完成报错——

java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getConnectionProvider()....
解决方案——
You're using Spring 3.2.5, and it's not compatible with the latest Hibernate 4.3.3 version that you're using. Hibernate 4.3 indeed decided to change the package of the ConnectionProvider returned by SessionFactoryImplementor.getConnectionProvider(). Use the latest Spring version, or use Hibernate 4.2, and it should run better.

有道翻译一下:

你使用Spring 3.2.5,这不符合最新的Hibernate 4.3.3你使用的版本。Hibernate 4.3确实决定改变包的返回的ConnectionProvider SessionFactoryImplementor.getConnectionProvider()。使用最新的春季版本,或使用Hibernate 4.2,它应该更好的运行。

2.如果你的项目没有配置Spring事务管理,一般处理与数据库相关业务时报错误为——

org.hibernate.HibernateException: No Session found for current thread

3.报错——

org.hibernate.HibernateException: No Session found for current thread
解决方案——

看看你是否在处理业务的类上加上了@Transactional注解

0 0
原创粉丝点击