0 Replies Latest reply on Dec 1, 2005 9:31 AM by Marco Cerqui

    Object not stored / HibernateContext

    Marco Cerqui Newbie

      Hello everybody

      I have a problem storing my objects with Hibernate. The following code is part of a EJB Session Bean and is called by a JSP:

       public String getEchoString(String clientString) {
       InitialContext ctx;
       try {
       ctx = new InitialContext();
       SessionFactory factory;
       factory = (SessionFactory) ctx.lookup("java:/hibernate/SessionFactory");
       Session hsession = factory.openSession();
       Transaction tx = hsession.beginTransaction();
       Entry newEntry = new Entry();
       newEntry.setEntrydate(new java.util.Date());
       } catch (NamingException e) {
       return clientString + " - from session bean";

      The problem is, that without having a hsession.flush() the object gets not stored in the database. Can somebody tell me why? Shouldn't a tx.commit() oder a hsession.close() be enough?

      I also have tried the HibernateContext.getSession() version, but I had the same result. Furthermore Eclipse told me that HibernateContext.getSession() deprecated. Is this true? What is the best method to get a Hibernate session?

      I use JBoss 4.0.3 SP1, Oracle and Hibernate 3.

      Thank you,