-->
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: Beginner question about Hibernate Session
PostPosted: Tue Jun 09, 2009 5:02 am 
Newbie

Joined: Tue Jun 09, 2009 4:49 am
Posts: 5
Hi all !
I'm writing a Desktop application which uses Hibernate for querying DB Objects.
I have a manager class which Starts an Hibernate Session and returns the Objects to the application:

Code:
      public static List<MyObject> findRoot() {
         Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
         session.beginTransaction();
         Query query = session.createQuery("FROM MyObject");
               session.getTransaction().commit();
               return (List<MyObject>)query.list();
      }

The problem is that, if I issue a session.commit(), then I'm not able to return Objects, rather Hibernate issues "org.hibernate.SessionException: Session is closed!"

What is the correct way to return Objects ?

Should I issue a commit from my Desktop application, after I have Iterated on the Objects ? (I don't like this solution, becuase I'd like to keep separated the Hibernate logic from the front-end layer)

What happens instead if I don't issue the commit after the Query ? the session will stay open and therefore I'll have DB leaks ?

thanks a lot
John


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.