1 Reply Latest reply on Jul 17, 2011 2:55 AM by adamw

    Determine change for single property

    etwcn

      Hi,

       

      I am currently doing my first steps with Hibernate Envers. So far it looks really impressive! Now, I have a use case, where I need to determine at which revision a given property has changed. Since envers always saves a complete snapshot of an entity, this is not necessarily the latest available revision of that entity.

       

      Here is an example: I have an entity Person that is initially filled with the name "Donald Duck". After that is saved, I modify the surname from "Donald" to "Dagobert". This gives the following audit table for the Person entity:

       

      select r.revtstmp, p.* from revinfo r join person_aud p on p.rev = r.rev

       

      revtstmpidREVREVTYPEREVENDnamesurnameaddress_id
      13099369381331203DuckDonald1
      1309936938484131(null)DuckDagobert1

       

      Now, I want to determine the revision when the name property was last changed. For the example, this would be revision 0.

       

      What I can do with the available data so far is to query all revisions of the entity and then compare the desired property at all revisions until I find a change (or, like in the example, until I find the initial revision).

       

      Is there a possiblity to find that revision with a query instead of having to manually inspect all available revisions?