[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Transferring entities on the client side

dimar1975 do-not-reply at jboss.com
Fri Jun 12 07:51:35 EDT 2009

Hi all !
I'm writing an 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:

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 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)

Should I rather clone the objects and return the detached cloned object to the client ?

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

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4237260#4237260

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4237260

More information about the jboss-user mailing list