hibernate spring-mvc集成:
错误说明:
通过junit测试dao时,报错:createQuery is not valid without active transaction,错误为没有有效的事物,即session中没有关联事物。
问题分析:
openSession()与getCurrentSession()区别,
参考:http://zhou137520.iteye.com/blog/1630656
解决办法:
1、手动添加事物管理,即Transaction tx = session.beginTransaction();.....tx.commit();
2、session = sessionFactory.getSession();
个人看法:
进行测试时使用openSession(),在web上运行时采用getCurrentSession()。
spring hibernate integration transaction error
猜你喜欢
转载自chj738871937.iteye.com/blog/1782609
周排行