Envers bundled with JBoss AS 7.0.2!
Join the DZone community and get the full member experience.Join For Free
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:
- add hibernate-envers to the pom.xml using the provided scope
- add @audited to the entities that you want to audit
- 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:
- run mvn clean install, and copy the resulting .war to jboss/standalone/deployments
- 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!
Opinions expressed by DZone contributors are their own.