0 Replies Latest reply on Jun 12, 2009 7:51 AM by ermes martino

    Transferring entities on the client side

    ermes martino Newbie

      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
      Marco