I wrote my BaseDAO, and if I closed the session in each method, and following Test would failure.Code:package org.nirvana.jswiki.dao.impl; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.nirvana.jswiki.dao.BaseDAO; public class BaseDAOImpl implements BaseDAO { protected SessionFactory sessionFactory; public void create(Object o) { Session session = sessionFactory.getCurrentSession(); session.save(o); } public void save(Object o) { Session session = sessionFactory.getCurrentSession(); session.save(o); } public void update(Object o) { Session session = sessionFactory.getCurrentSession(); session.update(o); } public void saveOrUpdate(Object o) { Session session = sessionFactory.getCurrentSession(); session.saveOrUpdate(o); } public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } }
If I did not close the session, this Test would be OK.Code:UserDAO dao = (UserDAO) ctx.getBean("userDAOProxy"); User u = dao.retriveByName("Nicholas"); u = new User(); u.setName("Helen"); u.setEmail("Helen@hotmail.com"); dao.save(u); assertEquals("Helen", u.getName());
Does Spring manage per sesson out-of-box?[/code]


Reply With Quote
