日期:2014-05-20  浏览次数:20660 次

No Hibernate Session bound to thread, and configuration does not allow creat
第一个方法
public void addLog(Log log) {
Session session = sessionFactory.getCurrentSession();
session.save(log);
}
第二个方法
public void addUser(User user) {
Session session = sessionFactory.getCurrentSession();
session.save(user);
}
调用上面两个方法
@Transactional
public void addUser(User user) {

userDAO.addUser(user);
logDAO.addLog(new Log());
}
运行测试:
@Test
public void testAspect()
{
ApplicationContext ctx = new FileSystemXmlApplicationContext("src\\applicationContext.xml");
UserService userService = (UserService)ctx.getBean("userService");
userService.addUser(new User());
}

我已经加了@Transactional啊,怎么老是出错:No Hibernate Session bound to thread, and configuration does not allow creat

------解决方案--------------------
友情帮顶了,
------解决方案--------------------
<!-- 支持 @Transactional 标记 -->
<tx:annotation-driven proxy-target-class="true" transaction-manager="txManager" />
------解决方案--------------------
proxy-target-class="true"

表示事务加在类上而不是接口。
------解决方案--------------------
菜鸟来帮顶了.. 

为什么你用hibernate不要beginTransaction();

这有个跟你一样错误的解决办法:http://hi.baidu.com/landor2004/blog/item/14eed5461639a20e6b63e530.html