Hibernate Envers auditing

Skip to first unread message

Richard van Duijn

Aug 19, 2011, 5:02:31 AM8/19/11
to play-fr...@googlegroups.com
Hi everyone!

I'm trying to figure out the best approach to use hibernate envers with Play.

The goal is to store revision data alongside the audit. The data required is the user which performed the crud operation and a String value containing a small description of the change made. I'm using a RevisionListener implementation which passes me a RevisionEntity object to which i've added those two fields.

public class AuditModelRevisionListener implements RevisionListener
   public void newRevision(Object revisionEntity)
   {   AuditRevistionData auditModel = (AuditRevistionData) revisionEntity;
       auditModel.editor = Security.getConnectedSystemAccount().user;
       auditModel.description = ????;

Note that the passed revisionEntity is NOT the entity on which the action is performed upon. Retrieving the user reference is easy using the Security class.
I would like to derive the description of the CRUD operation from the method that was called. 

So my main question is: is there a way in Play to retrieve the method reference that is currently being called by the user?
This would be very useful as I can use the name to store a descriptive revision message. Also I could extend this in the future by adding a custom annotation to the method which allows for a more descriptive revision message.

Thanks in advance!


Richard van Duijn

Aug 19, 2011, 7:38:05 AM8/19/11
to play-fr...@googlegroups.com
Ok, after some digging around in the API i've found the answer..(if someone might want to do the same...)
Play is even better than I even thought. The concept of wrapping everything in Threadlocals is very handy!

The sollution:

Request request = Http.Request.current.get();

Method invokedMethod = request.invokedMethod;

And voila, you've got the method. This also allows me to add custom annotations to the method for better audting.
Should you have any queries, don't hesitate to send me a note. I'll be happy to assist. Hope to make a nice blogpost of this soon.
I'll reply to this topic if i got it ready..


Reply all
Reply to author
0 new messages