3 Replies Latest reply on Jan 30, 2009 9:56 AM by Adam Warski

    Versions created only on transaction commit ?

    Amar Singh Newbie

      Is that the case that a version of Audited Entity is created only when the transaction is committed ? (assuming that the Audited Entity was modified).

      Is there a way to get the versions created on each

      saveandUpdate(...) or on update(...).
      
      


        • 1. Re: Versions created only on transaction commit ?
          Adam Warski Master

          Hello,

          revisions are created only when a transaction is commited. That's beacuse flushing may occur at unpredicatble times, depending on your configuration, so when you execute update(), or a query. I think creating revisions on transaction commits is what you really want :)

          --
          Adam

          • 2. Re: Versions created only on transaction commit ?
            Amar Singh Newbie

            I was looking at the implementation and I believe the WorkUnits only get executed in case of Transaction commit, which means flushing will be ensured even if we allow versions creation at each saveandUpdate but final creation of version is only on transaction commit ?

            My use case is to create 7 versions of an Object and if any intermediate version creation fails then don't create any version. This could have been easy if I follow the following algo:

            transaction.start();
            object obj....
            ..
            ..
            sessions.saveandUpdate(obj)...
            ...
            ...
            do this seven times and see if anything fails ....if no failure then commit the transaction
            ...
            ...
            transaction.commit();
            


            Any ideas ?

            • 3. Re: Versions created only on transaction commit ?
              Adam Warski Master

              Hello,

              you're right, the work units get executed only when the transaction as commited. Only then I can be sure what is the data content of the revision.

              Why would anything fail when creating versions?

              If anything does, then the whole transaciton will be rolled back, and no changes will be made.

              --
              Adam