Adam Warski

12 Jun 2008

Envers beta – now with queries!

envers
java
hibernate

So far Envers made it easy to store historical data; now, with version 1.0.0.beta1 (download here), you can also query it, in two “dimensions”: for entities at a given revision and for revisions, at which an entity changed. The implementation mostly follows Hibernate Criteria, with some features removed, and some added.

For example the following query returns all persons with the name “John”, sorted by their surname, which lived at the address with the given id at revision 12:

List personsAtAddress =
      getVersionsReader().createQuery()
      .forEntitiesAtRevision(Person.class, 12)
      .addOrder(Order.asc("surname"))
      .add(VersionsRestrictions.relatedIdEq(
            "address", addressId))
      .add(VersionsRestrictions.eq("name", "John"))
      .getResultList();

You can find more information about creating queries on this page.

Warning – the schema generated by this version of Envers is incompatible with the schema generated by the preview versions. If you have any data to migrate, please write on the forum. As this is the beta release, there will be no more schema changes until the 1.0 final release.

Thanks to the forum users: talios, aamonten, genman, liuxiaodu and others for bug reports, patches, testing and ideas!

Finally, the release notes for this release are located here.

As always, waiting for comments and bug reports :)

Adam

comments powered by Disqus

Any questions?

Can’t find the answer you’re looking for?