0 Replies Latest reply on Dec 1, 2005 9:31 AM by m.cerqui

    Object not stored / HibernateContext

    m.cerqui

      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.setEntry(clientString);
       newEntry.setEntrydate(new java.util.Date());
      
       hsession.save(newEntry);
       //hsession.flush();
       tx.commit();
       hsession.close();
       } catch (NamingException e) {
       e.printStackTrace();
       }
       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 10.1.0.3 and Hibernate 3.

      Thank you,

      Marco