5 Replies Latest reply on Jun 27, 2011 11:08 AM by adamw

    Object is not retrieved correctly

    n.mirzadeh

      I've a case where

       

      @Audited

      public class StateTransition {

          @Audited(targetAuditMode= RelationTargetAuditMode.NOT_AUDITED)

          private Event             event;

          ..

      }

      ----------       

      @Audited

      public class Event {

        

         private long    id;

         private String name;

         // getter, setter for id and name

      }

       

      Event objects can be added and never deleted. When I query revisions of StateStransition, I get an object representing a (historic) revision of StateStransition, and from that object I can retrieve Event, but as soon as I call event.getName() I get the following error:

                      No row with the given identifier exists: [com.bellid.cams.model.Event#57]

        • 1. Re: Object is not retrieved correctly
          hernanbolido

          Hi!

           

          I think that having the relation from StateTransition to Event marked targetAuditMode= RelationTargetAuditMode.NOT_AUDITED and having the entity Event audited is a bit confusing...

          Do you want to audit Event or not?

          The semantic of the relationTargetAuditMode.NOT _AUDITED is that the related entity hasn`t history. There is not a hoctoric table and instead of that, envers resolve the relation to the entity through hibernate session.

           

          I hope it will be helpful.

           

          Regards. Hernán.

          • 2. Re: Object is not retrieved correctly
            n.mirzadeh

            Hi Hernan,

            I realised this behaviour yesterday. In my case the Event and StateTransition objects are manipulated in different transactions, hence, they get different revision numbers. If  I remove the relationTargetAuditMode.NOT _AUDITED annotation from the Event, then Evenrs  would resolve the association from the Event historic table with the same revision number as the (historic) audited-StateTransition object. In other words, in this case getting the Event object from the historic StateTransition would always return null as the result of removing relationTargetAuditMode.NOT _AUDITED. Another option is NOT to audit the Event. But, the later means that I would lose the logs on creation and changes made to the Event objects.

             

            So, how can I get around this issue?

             

            Regards,

            Nader

            • 3. Re: Object is not retrieved correctly
              adamw

              Again, I don't quite understand why you would get a null there . I think you would get null only if the Event/StateTransition didn't exist at a given revision. Otherwise, you should get correct data.

               

              Maybe you can create a small test case on what you are trying to achieve, so that it will be easier for both of us to understand what's going on?

               

              Adam

              • 4. Re: Object is not retrieved correctly
                n.mirzadeh

                Hi Adam,

                looking at the code, Envers uses the annotation on an entity to determine whether to retrieve it from the historic-table or the table where the entity is stored. It be more correct to leave this decision to the annotation on the relation, then the expected data should correctly be retrieved.

                • 5. Re: Object is not retrieved correctly
                  adamw

                  Hmm I don't get the difference in the approaches you described

                   

                  Adam