0 Replies Latest reply on Jul 22, 2006 12:24 PM by xpoft

    Saving data in Hibernate

    xpoft

      JBoss 4.0.4, Hibernate 3.0. Data do not saved!

      Code in EJB component:

      ctx = new InitialContext();
      SessionFactory factory = (SessionFactory) ctx.lookup("java:/hibernate/SessionFactory");
      Session hsession = factory.openSession();
      Transaction tx = hsession.beginTransaction();
      Orgs orgs = new Orgs("Hibernate test");
      hsession.save(orgs);
      tx.commit();
      hsession.close();
      


      In hibernate.org FAQ: wrote

      I saved / deleted / updated an object / collection but I can't see the changes in the database!

      Hibernate will not execute any SQL until you either call Transaction.commit() (if using the Transaction API) or Session.flush() (if you are not) at the end of a session to flush your in-memory changes to the database.

      If you are not using the Transaction API, you must then explicitly commit the transaction (by committing the JTA transaction or JDBC Connection).


      Therefor on "Transaction.commit()" SQL query must be execute. But do not do that, while not execute "hsession.flush()".

      But in FAQ wrote, that "Session.flush()" must be using when we do not have Transaction.

      Where I'm wrong?