This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Auditing using Hibernate Envers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Auditing using Hibernate Envers" Watch "Auditing using Hibernate Envers" New topic
Author

Auditing using Hibernate Envers

Vivek Kr Agrawal
Ranch Hand

Joined: Sep 08, 2012
Posts: 51

I am doing lots of R&D to do auditing for a big project. The project will be entirely beased on Spring framework with JPA and Hibernate to do the data mapping part. For auditing I have came across various features and technology.
Hibernate interceptors.
Hibernate Event listeners.
Hibernate Envers
Spring AOP.
I even tried creating and maintaining my own AUDIT table.

So far I am considering Hibernate Envers as my best bet as it reduces the manual coding and its versioning features is very interesting. Since it is a relatively new technology I don't have very much idea and I want to be pretty sure before implementing this as a part of solution.

So please suggest me which will technology will be best suited? Will Hibernate Envers be able to deal with complex business scenarios? Need some expert advice.


Vivek Agrawal
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Envers is not new. It is mature project that has been fully adopted officially by the Hibernate project. I would not have any reservations about using it in production. Hibernate Envers has 2 modes of operation, and is pretty flexible. I don't know your requirements but I would say certainly yes it can deal many aspects of typical auditing. It actually works in a similar fashion to SVN.


[How To Ask Questions][Read before you PM me]
Vivek Kr Agrawal
Ranch Hand

Joined: Sep 08, 2012
Posts: 51

Thanks for the reply,
I am doing a small POC on by using Envers. So far I have only one doubt. Consider that I have 5 tables that needs to be audited. I am putting to specify that this table needs auditing. But I was wondering is there any better method to specify that?
I mean, is there any way that we can give a user(in my case he will be administrator) the ability to decide which table he wants to audit. It does not make
much sense to me that he will be keep on changing the code himself if tomorrow he wants to add one more table for auditing?
Please consider that , it is an important requirement that all annotations should be moved into a xml metadata file(like orm.xml) to provide better configuration
facilities.
Does Envers has anything up in its sleeves for it?
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Yes you can do conditional auditing. I have never had the need to do this personally but here is the relevant part of the documentation

http://docs.jboss.org/hibernate/core/4.1/devguide/en-US/html/ch15.html#d5e4275

You would subclass the appropriate listener and check a property or whatever before proceeding with the audit. You would have to expose a way to set said property at runtime most likely through the UI, JMX or a database property table.


As for an XML based configuration, it does not exist. There is a JIRA out there for it, but I don't think its at the top of anyone's priority list as people are generally moving away from that approach. However I think you can accomplish what is needed with what I said above. Whether the mappings are in annotation, or XML that is not something that should be messed with outside of a new build-release cycle anyway, so I don't necessarily agree with the statement that it provides better configuration facilities.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Auditing using Hibernate Envers