1 Reply Latest reply on Apr 30, 2009 7:20 AM by gusgorman

    Transactions and strange behaviour

      Hi,

      I have some behaviour that I just don't understand.

      I have an entity Release, which has a one to many relationship with Question.

      Question has a composite key (i know...) and therefore we use a version attribute: <version name="Version" unsaved-value="0"/>


      The following behaviour is occuring:

      1) Load a release.
      2) Loop round its collection of Question objects. (don't modify them)
      3) Call any code that begins and commits a transaction, and for every Question loaded in stage 2, if the version
      number > 1 then an update is done on that Question, thus incrementing the Version number.

      If I do modify a Question in any way during stage 2 then this change is persisted in stage 3, which I also don't understand, surely I should have to call SaveOrUpdate?

      Why is going on here?

      Any help with this would be greatly appreciated.
      I am using nHibernate 2.

      regards,
      Jordan.

        • 1. Re: Transactions and strange behaviour

          Hello again, more info now.

          I now understand that the session is being flushed when I commit a transaction, and that is why updates are occuring to Question objects at that point. But why does hibernate think that these objects are dirty? They definately shouldn't be.

          I have implemented Audit logging using the idea suggested here:

          http://209.85.229.132/search?q=cache:Wg61eqMQfGcJ:www.hibernate.org/48.html+usertype+for+audit+info+logging+site:hibernate.org&cd=1&hl=en&ct=clnk&gl=uk

          Each entity that needs audit logging has the following xml in its mapping file:

          <property name="AuditInfo" type="BCS.QMIS.DataAccess.Hibernate.CustomTypes.AuditInfoType, QMISDataAccess">
           <column name="WhenAdded" />
           <column name="WhenUpdated" />
           <column name="AddedBy" />
           <column name="UpdatedBy" />
           </property>
          


          If I remove this piece of xml from the Question.hbm.xml file then stage 3 of my first post does not happen, ie no unwanted updates occur and the version is not incremented. Any ideas?

          Many thanks in advance,
          Jordan.