spring整合hibernate关于 session的管理<三种方式>
转载:spring整合hibernate关于 session的管理
http://solodu.iteye.com/blog/454469
示例代码如下:
类代码:
public class UserDAOImpl extends HibernateDaoSupport implements UserDAO { //三种方式}
public List<User> getAll() { return super.getHibernateTemplate().find("from User"); }
public List queryAll() throws Exception { //ession session=super.getSession();错误 Session session=super.getSession(true); String hql="from Item as i"; try{ List l=session.createQuery(hql).list(); }finally{ session.close(); } }
public List queryAll() throws Exception { Session session = super.getSession(); String hql = "from Item as i"; List l = session.createQuery(hql).list(); releaseSession(session); }