SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread
来源:互联网 发布:淘宝客鹊桥什么意思 编辑:程序博客网 时间:2024/05/21 06:28
查了一下相关资料,整理如下:
原因:Hibernate4 No Session found for current thread原因
解决方法:
1. 在spring 配置文件中加入
程序代码
<tx:annotation-driven transaction-manager=”transactionManager”/>
并且在处理业务逻辑的类上采用注解
程序代码
@Service
public class CustomerServiceImpl implements CustomerService {
@Transactional
public void saveCustomer(Customer customer) {
customerDaoImpl.saveCustomer(customer);
}
…
}
另外在 hibernate 的配置文件中,也可以增加这样的配置来避免这个错误:
程序代码
<property name=”current_session_context_class”>thread</property>
解决方法二:http://zhidao.baidu.com/link?url=BNyi8By29DMOXBCiNLeTa7WTTxlf4Q4IbQkrYO6lv6MFNMxv5zkBIx723t4JkezOaNcxc9ARhDIeXxtRZbID_0jYKonThVemDs1VkBUFmpK
我也出现了这个问题,但是我在web.xml中增加了filter就可以了。也许你的问题不是这个,但我的这个问题是这么解决的。 <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>
以上亲测,都可以解决!
以上是转载,下面是亲测,实际解决问题
因为注入的是实现类而不是接口类
@Autowired TransManagerImp tm;
所以Spring配置事务拦截service接口修改为拦截serviceiml,问题解决
阅读全文
0 0
- SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread
- SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread
- SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread
- SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread
- SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread
- SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread
- SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread
- Hibernate4中使用getCurrentSession报Could not obtain transaction-synchronized Session for current thread
- Hibernate4中使用getCurrentSession报Could not obtain transaction-synchronized Session for current thread
- 报错 Could not obtain transaction-synchronized Session for current thread
- spring整合hibernate报错:Could not obtain transaction-synchronized Session for current thread
- Hibernate报错:Could not obtain transaction-synchronized Session for current thread
- spring4+hibernate4+junit整合问题 Could not obtain transaction-synchronized Session for current thread的问题
- springmvc+spring4+hibernate4整合Could not obtain transaction-synchronized Session for current thread
- Hibernate4 提示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
- 【Unity】使用GPS定位经纬度
- 一篇文章,教你学会Git
- 2017.09.07工作日记
- SQL Server 的命名规则
- 欢迎使用CSDN-markdown编辑器
- SpringMVC4+Hibernate4运行报错Could not obtain transaction-synchronized Session for current thread
- linux
- 水果忍者VR原型 二
- C++杂记(1)
- spring-boot logging自定义控制台日志颜色
- spring对session和事务的管理以及OpenSessionInViewFilter是如何工作的
- oracle序列
- 通过git-bash提交项目代码
- Fedora26使用PPPoE以及为Firefox安装Flash