-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: design question
PostPosted: Sun Sep 26, 2004 11:57 am 
Newbie

Joined: Sun Sep 26, 2004 11:36 am
Posts: 7
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.