报错:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
ssh框架(struts2,springmvc,hibernate)
报错语句:Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
原因:使用了原生的sql语句,由于之前一直使用的是hql,但后来因为想用limit对数据库进行操作,但hibernate不支持limit,所以改用了sql语句,以致于程序出错。
简单粗暴的解决方式是 Session session = getHibernateTemplate().getSessionFactory().openSession();
但众所周知 openSession(),getCurrentSession() 有别,区别忘了0.0
还有一种就是对查询语句开启事务管理。