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