• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auditing using Hibernate Envers

 
Vivek Kr Agrawal
Ranch Hand
Posts: 51
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vivek Kr Agrawal
Ranch Hand
Posts: 51
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic