1 Reply Latest reply on Dec 26, 2007 12:56 PM by Pete Muir

    flush() occurs though the transaction is rollbacked?!

    Andrew Batman Newbie

      is it normal or bug, that flush() always occurs, even if the transaction rollbacks?

      i have seam-managed hibernate session configured according to seam documentation http://docs.jboss.com/seam/2.0.0.GA/reference/en/html/persistence.html#d0e5849

      <property name="transaction.flush_before_completion">true</property>
       <property name="connection.release_mode">after_statement</property>
       <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
       <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>

      and a method
       public void save(Person person){
       currentSession.createSQLQuery("{call initializePerson(:person_id)}")
       .setLong("person_id", person.getId())
       if (!person.isInitialized()) throw new RuntimeException("Failed to initialize person");

      as a result of the method's execution:

      if person is uninitialized , it will be a rollbacked transaction due to the RuntimeException. (Because it is a "System Exception" and they always cause a transaction rollback http://docs.jboss.com/seam/2.0.0.GA/reference/en/html/events.html#d0e4391)

      As expected the stored procedure "initializePerson" will be rollbacked.
      But an insert of the method "currentSession.save(person)" will be executed. Because the property transaction.flush_before_completion's value is true.

      if hibernate.transaction.flush_before_completion is enabled, the session will be automatically flushed during the before completion phase of the transaction.(http://www.hibernate.org/hib_docs/reference/en/html/session-configuration.html)

      Thus we have 'partial' committed transaction. Imho, it isn't normal behaviour, when an exception occurs.

      Any suggestions to cause full rollbacking ?

      (without disabling "flush_before_completion" property or enabling FlushModeType.MANUAL, that seems the same))

      Note that Seam does not flush the session, so you should always enable hibernate.transaction.flush_before_completion to ensure that the session is automatically flushed before the JTA transaction commits.http://docs.jboss.com/seam/2.0.0.GA/reference/en/html_single/#d0e5849