错误记录(九)Could not obtain transaction-synchronized Session for current thread
来源:互联网 发布:云影源码1llo 编辑:程序博客网 时间:2024/05/21 05:37
报错信息:
org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current threadat org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1041)
这个错误的提示是无法获取当前transaction-synchronized线程的会话
原因是没有为用到了事务的方法定义事务
比如:在Action中定义了该方法,用于删除数据信息操作:
而在applicationContext.xml中是这样设置的:
这表示只有以do和find打头的方法才能事务,其他方法不走事务,删除自然不能成功,于是报上面的错误。
当然,也可能不是上面这么粗心的原因,如果使用了Hibernate4报错的话,可以在web.xml中加入如下配置,程序也可以正常运行了。
<filter><filter-name>SpringOpenSessionInViewFilter</filter-name><filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class></filter> <filter-mapping> <filter-name>SpringOpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
网上还看到一种解决方法,针对第二种情况的,测试也可行。
1. 在spring 配置文件中加入
2. 在处理业务逻辑的类上采用注解:<tx:annotation-driven transaction-manager="transactionManager"/>
如:
@Servicepublic class CustomerServiceImpl implements CustomerService { @Transactional public void saveCustomer(Customer customer) { customerDaoImpl.saveCustomer(customer); } ...}
阅读全文
1 0
- 错误记录(九)Could not obtain transaction-synchronized Session for current thread
- 【Hibernate】Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- HibernateException: Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- Could not obtain transaction-synchronized Session for current thread
- 异常
- html td文字垂直对齐
- 575. Distribute Candies
- JSP
- solr服务器搭建成功后的测试
- 错误记录(九)Could not obtain transaction-synchronized Session for current thread
- 最全eclipse自由轻松来回切换项目的jdk版本的方法
- JMM
- JAVA类+抽象类和接口的继承
- 希尔排序(Shellsort)简介
- Maven的构建配置文件(Build Profiles) 在命令行使用构建配置文件时,是-P,比如:mvn -Pinput 注意:这里的构建配置文件并不是一个真正的文件,而是通过指定参数来做特定
- linux入门第5篇-用户组和权限
- 阿里云ubuntu16.4部署docker
- 使用中间件