Hibernate version:
2.1.6
Name and version of the database you are using:
MySQL 4.0
Debug level Hibernate log excerpt:
2004-09-26 17:34:29,497 ERROR com.test.xeg.webservices.Userservice SoapBindingImpl - net.sf.hibernate.HibernateException: Session is closed
Hi All,
I am using Hibernate in conjunction with Axis. I instanstiate a new UserDAO per request which has a method :
public void saveUser(User user) throws UserExistsException, DAOException
{
Session session = null;
try
{
HibernateManager.beginTransaction();
session = HibernateManager.getSession();
List results = (List) session.find("from com.playingwithmatches.xeg.webservices.User as user where user.username= ?",
user.getUsername(), Hibernate.STRING);
if(results.size() > 0)
{
throw new UserExistsException(user.getUsername(), "username already exists");
}
session.flush();
session.save(user);
HibernateManager.commitTransaction();
}
catch(HibernateException he)
{
logger.error("hibernate failed to save user " + he.getMessage());
HibernateManager.rollbackTransaction();
throw new DAOException(he);
}
finally
{
if(session != null)
{
HibernateManager.closeSession();
}
}
}
When testing with multiple requests I am getting net.sf.hibernate.HibernateException: Session is closed - this is because the HibernateManager.closeSession() is acting on the threadsession in HibernateManager outside the scope of the current request (?)
The code for the HibernateManager is identical to the HibernateUtil code in caveatemptor example.
My question is how I can do it so multiple requests wont cause problems in a "good" way ?
Apologies if this is rtfm - ive scoured forums / tuts for example to help me out without any luck.
|