Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Auditing using Hibernate Envers

 
Ranch Hand
Posts: 51
Eclipse IDE Spring Java
  • 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.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • 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 Spring Java
  • 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 Mac OS X IntelliJ IDE Spring Linux
  • 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.
 
Don't touch me. And dont' touch this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic