I am the founder and lead developer of Hibernate Envers, a Hibernate core module, which provides entity versioning/auditing capabilities. I am also one of the co-founders of SoftwareMill, a company specializing in delivering customized software solutions (http://softwaremill.com, "Extraordinary software as a standard"), based on Java and JBoss technologies. After work, apart from being involved in development of Envers, I work on several small open source projects, like ElasticMQ (simple message queue written in Scala with an SQS interface), projects around static analysis (using JSR 308 - Typestate Annotations/ Checkers Framework and FindBugs), and some CDI/Weld (not always portable) extensions, like autofactories or stackable security interceptors. I am also interested in new JVM-based languages, especially with functional elements (like Scala, JRuby) and frameworks built using them (like Lift), as well as improving the ways we use Dependency Injection. Adam is a DZone MVB and is not an employee of DZone and has posted 52 posts at DZone. You can read more from them at their website. View Full User Profile

Envers bundled with JBoss AS 7.0.2!

  • submit to reddit

Using Envers is now even easier! Since version 7.0.2, Envers comes bundled with JBoss Application Server.

To showcase how easy the integration is, I created a small JSF/CDI application, which uses Envers and can be deployed straight to AS7. To build the application I decided to try out JBoss Forge, which turned out to be very easy to use and provided me with a simple one-entity CRUD in no time. Just a few changes made it possible to track changes made to the entity, and view its history.

So if you are using AS 7.0.2, to add Envers to your app you just need to:

  1. Add hibernate-envers to the pom.xml using the provided scope
  2. Add @Audited to the entities that you want to audit
  3. Enable the Envers module by specifying a dependency in MANIFEST.MF

The last step makes the bundled Envers module visible to your application. To view all the changes necessary in detail, just take a look at this commit.

Apart from storing the changes, you may also want to view the history of an entity. That’s also pretty straightforward. All we need is to create a new JSF view and a CDI bean with a method running a simple history query. Again, this commit shows all the changes needed.

You can deploy the application in two ways:

  1. Run mvn clean install, and copy the resulting .war to jboss/standalone/deployments
  2. If you are using Forge, run forge from the checkout directory, and invoke: build, then: as7 deploy

After deployment, you should be able to access the application using http://localhost:8080/envers-as7-demo. Click on the Person link on the left to add, edit, list and view history of the entity.

By default, the application uses an example datasource, but if you wish to explore the additional schema generated by Envers you can easily change it to another database by modifying persistence.xml and creating a new datasource in the AS administration console.

As always I invite you to submit feedback on the Envers forum. Have fun!



From http://www.warski.org/blog/2011/09/envers-bundled-with-jboss-as-7-0-2/

Published at DZone with permission of Adam Warski, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Mohamed Reda replied on Mon, 2011/10/03 - 7:02am

As a Newbie, I am continuously searching online for articles that can benefit me. Thank you. solar mower

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.