4 Replies Latest reply on Nov 18, 2008 9:58 AM by Chris Simons

    My minimal approach to Envers...will it work?

    Chris Simons Expert

      Hi All,

      Envers is a very interesting project and one that would accommodate some of the requirements of the app I am working on.

      I am not as interested in mapping the _changes_ between entity revisions, but rather just storing when those changes were made and who made them. I see from the examples that you can track this information in a separate entity and then use an entityListener to call the appropriate methods on insert, update, delete, etc.

      But is there a better way than creating three separate classes for each entity that I might want to track this data?

      Do you think Envers is "overkill" for what I need? I can see the future requirement for versioning some entities...but I want a global, wholistic approach to tracking simple revision data (who, when) for all of my entities.


      Also, how would one query revision changes to see only the "most recent revision"?

      I found this in a presentation PDF but would like to see how you would modify this to pull only the last one?

      VersionsReader vr =
      VersionsReaderFactory.get(em);
      // Reading the person at revision 1
      old_p = vr.find(Person.class, id, 1);
      assert “John�.equals(old_p.getName());
      assert a1.equals(old_p.getAddress());


      Thank you.

        • 1. Re: My minimal approach to Envers...will it work?
          Adam Warski Master

          Hello,

          first of all, the "RevisionEntity" is global - you can have only one, and it's created whenever a versioned class changes. (In the future, you'll be able to have severl revision entities, by having severl "revisioning groups").

          So you don't want to track the changes to your data, just capture the meta-data (date, user, etc?)?

          The most recent version is always in the (original) entities - so I don't quite understand what you mean here?

          --
          Adam

          • 2. Re: My minimal approach to Envers...will it work?
            Chris Simons Expert

            adamw,

            Sorry for the late response...I must have forgotten to check for email notifications on a reply.

            Essentially, I'd like to use a "plug-in-play" versioning system but I don't need to actually compare data between versions. All I care about from one entity version to another is who made the change (i.e. a User) and when (i.e. a Date/Time). That's all I essentially care about in our specific use case.

            I'd like to better understand whether Envers is something that should be used for this use case.

            Thanks.

            • 3. Re: My minimal approach to Envers...will it work?
              Adam Warski Master

              Hello,

              you can use Envers here - however I'm not sure if it won't be a bit of an overkill.

              The solution would be to version no fields in each entity (except the ID), and create a custom revision entity, which would hold the username (and date, which is held by default anyway). Then, you could retrieve the revision entity + modified entity pairs witha revisions-of-entity query.

              Adam

              • 4. Re: My minimal approach to Envers...will it work?
                Chris Simons Expert

                Adam,

                Thank you - this is the kind of information I wanted to know in order to determine if Envers was right for my project. I appreciate your time. I might give it a go and do exactly as you said...