3 Replies Latest reply on Jan 11, 2011 2:41 PM by adamw

    Finding which attributes changed

    benbertola1

      We have a requirement in our system to show the user a list of which attributes changed, not necessarily retrieve the whole object at a given point in time.  The output would be similar to "First name changed from Ben to Chuck".  I know I could retrieve each version and iterate over the attributes to compare, but could imagine a more generic approach where you could get a list of Property Change Descriptors back.  It would also be nice to query for revisions where a given property changed.

       

      Is this something Envers will support, or has anyone has done something similar to this?

        • 1. Re: Finding which attributes changed
          nseb

          +1 , I have the same urgent need

          • 2. Re: Finding which attributes changed
            billgloff6

            I also have the same need and since I didn't see it anywhere in Envers I created my own solution in roughly 100 LOC. For example, I need to see the diffs in all of the user revisions, so I run my auditReader query as such

             

            AuditQuery query = getAuditReader().createQuery()
                        .forRevisionsOfEntity(User.class, false, true).add(AuditEntity.id().eq(id));

             

            I then loop through all User objects and call BeanUtils.describe() on it which returns to me a Map of all readable properties. I then loop once more and compare the current Map to the previous revision Map and only record what is different between them and return a list to the client with all the recorded changes. I know it sounds like more work than what you probably wanted to do, but using BeanUtils.describe really cut down on the code to get all of those properties into a nice structure to work with.

             

            If anyone else knows a better way, please let me know!

            • 3. Finding which attributes changed
              adamw

              Hello,

               

              I think that's the best way to do it - there's nothing built into Envers which would help with that.

              But contributions are always welcome!

               

              Adam