-->
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.  [ 2 posts ] 
Author Message
 Post subject: Session Problem
PostPosted: Tue Sep 09, 2008 12:28 pm 
Newbie

Joined: Tue Sep 09, 2008 12:19 pm
Posts: 10
Hi All,
I'm having some problems with function session.openSession()
It doesn't open any session!?

Here is the code I have at the moment:
The currentSession() is called from listUser() function.


public static Session currentSession() throws HibernateException {
Session s = session.get();
//Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession(); <-- here is the problem...
session.set(s);
}
return s;
}


public static List<user> listUser(){
Session session = null;
Transaction tx = null;

try {
session = currentSession(); <-------it always jumps to" finally" closing the session?!
tx = session.beginTransaction();
List list = session.createQuery("from user").list();
tx.commit();
return list;
} catch (RuntimeException ex) {
if (tx != null) {
tx.rollback();
}
throw ex;
} finally {
userUtil.closeSession();
}
}



What seems to be a problem..... Any ideas?
The sessionFactory.openSession(); always fails!
Thanks
Greg.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2008 8:36 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Does the application behave differently if you use getSession as opposed to openSession?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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

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.