With the recent addition of queries to Envers, it is now possible to easily retrieve data in a bi-temporal way. If you are not familiar with bi-temporal versioning, a good introduction by Martin Fowler can be found here.
Suppose we want to store information about Persons and Addresses, at which these persons live. Moreover, we also want to store dates: when a Person registered the fact that he/she moved, and when did he/she actually move - these may be different, as a person may have first moved, and only registered the fact after a week. Storing the two dates: registered and actual, for some entity, is the basis of bi-temporal versioning.
We can store this information in a Registration entity, which is in a one-to-one relationship with Person, and one-to-many with Address. (Each Person can have at most one Registration, and therefore also Address; each Address can have many Registrations, and therefore many Persons living there.) The Registration entity can also store the registered and actual dates. Additionally, it can be versioned, so that all historical information is remembered.
Using queries, we can, for example, answer this question: “What did we know about the address of person X in the state of the database from date Y?”. To do this, we have to select a registration, which has the actual date as big (recent) as possible, but both the registration and actual dates must be before Y. Hence, the query can look like this:
versionsReader.createQuery()
.forRevisionsOfEntity(Registration.class, true)
.add(VersionsRestrictions.maximizeProperty("actualDate")
.add(VersionsRestrictions.relatedIdEq("person", personXId))
.add(VersionsRestrictions.le("registrationDate", dateY))
.add(VersionsRestrictions.le("actualDate", dateY)))
.getSingleResult();
You may experiment with bi-temporal versioning using the updated Envers+Seam demo. To run the demo, you’ll need JBoss AS 4.2. After downloading, unzip and deploy the -ds.xml and .ear files, start the server, and go to http://localhost:8080/envers_seam_demo. A screenshot from the demo:

Moreover, the second beta release of Envers is available. It contains minor feature additions (release notes).
Adam
Post to del.icio.us
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
Post to del.icio.us
Hello,
I’ve posted a poll on what data should be stored in versions tables in Envers, see here and cast your vote:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=136764
The results will determine the future implementation, so votes really count. And as always, comments & ideas are very welcome.
The two options, in short, are:
Adam
Post to del.icio.us
With the preview 3 release of Envers, you can easily associate additional data with revisions. This could be, for example, the name of the user making the change. You simply need to annotate an entity with @RevisionEntity: an instance of this entity will be persisted with each new revision. To provide a way to fill the entity with custom data, you need to implement an interface, and pass it as a parameter to the annotation.
For example, to store the name of the currently logged in user in a JBoss Seam application, the implementation of the listener would look as follows:
public class ExampleListener
implements RevisionListener {
public void newRevision(Object revisionEntity) {
ExampleRevEntity exampleRevEntity =
(ExampleRevEntity) revisionEntity;
Identity identity =
(Identity) Component.getInstance(
"org.jboss.seam.security.identity");
exampleRevEntity.setUsername(
identity.getUsername());
}
}
For more details see here.
There is also a demo Envers+Seam application: a very simple wiki. It allows users to create and edit pages, view their history and see which users made the changes.
And, as always, waiting for your comments on the forums! Thanks to the current forum members for the bug reports and ideas!
Adam
Post to del.icio.us
The “let” tag enables you to bind the value of any expression to a variable and later reuse it, without recalculating the value. The concept comes of course from functional programming. It is especially useful with Seam’s extended EL.
The usage is really simple:
<mamut:let var="result" value="#{anyElExpression}">
Now you can use #{result} as a normal variable.
</mamut>
I was looking at other tag libraries but couldn’t find anything similar. Or maybe there is?
The use case that motivated me to write this comes from the JBoss.ORG feeds application. There, in several places I have code similar to the following one:
<ui:repeat var="group" value="#{groupsService.all}">
<s:fragment rendered=
"#{groupsService.accFeeds(group).size() > 0}">
(some header)
<ui:repeat var="feed"
value="#{groupsService.accFeeds(group)}">
(...)
</ui:repeat>
</s:fragment>
<ui:repeat>
Of course calling groupsService.acceptedFeeds(group) twice is unnecessarily inefficient. I could move this call to a backing bean, but doing so would only cause me to write some really simple code many times. The version using the let tag calls the method only once:
<ui:repeat var="group" value="#{groupsService.all}">
<mamut:let var="acceptedFeeds"
value="#{groupsService.accFeeds(group)">
<s:fragment rendered="#{accFeeds.size() > 0}">
(some header)
<ui:repeat var="feed" value="#{accFeeds}">
(...)
</ui:repeat>
</s:fragment>
</mamut:let>
<ui:repeat>
If somebody finds this useful, I’ve put the jar here. To use it, just bundle the jar with your application. The namespace for the tag is the following:
xmlns:mamut="http://mamut.net.pl/jsf"
Adam
Post to del.icio.us
The “let” tag enables you to bind the value of any expression to a variable and later reuse it, without recalculating the value. The concept comes of course from functional programming. It is especially useful with Seam’s extended EL.
The usage is really simple:
<mamut:let var="result" value="#{anyElExpression}">
Now you can use #{result} as a normal variable.
</mamut>
I was looking at other tag libraries but couldn’t find anything similar. Or maybe there is?
The use case that motivated me to write this comes from the JBoss.ORG feeds application. There, in several places I have code similar to the following one:
<ui:repeat var="group" value="#{groupsService.all}">
<s:fragment rendered=
"#{groupsService.accFeeds(group).size() > 0}">
(some header)
<ui:repeat var="feed"
value="#{groupsService.accFeeds(group)}">
(...)
</ui:repeat>
</s:fragment>
<ui:repeat>
Of course calling groupsService.acceptedFeeds(group) twice is unnecessarily inefficient. I could move this call to a backing bean, but doing so would only cause me to write some really simple code many times. The version using the let tag calls the method only once:
<ui:repeat var="group" value="#{groupsService.all}">
<mamut:let var="acceptedFeeds"
value="#{groupsService.accFeeds(group)">
<s:fragment rendered="#{accFeeds.size() > 0}">
(some header)
<ui:repeat var="feed" value="#{accFeeds}">
(...)
</ui:repeat>
</s:fragment>
</mamut:let>
<ui:repeat>
If somebody finds this useful, I’ve put the jar here. To use it, just bundle the jar with your application. The namespace for the tag is the following:
xmlns:mamut="http://mamut.net.pl/jsf"
Adam
Post to del.icio.us
The “let” tag enables you to bind the value of any expression to a variable and later reuse it, without recalculating the value. The concept comes of course from functional programming. It is especially useful with Seam’s extended EL.
The usage is really simple:
<mamut:let var="result" value="#{anyElExpression}">
Now you can use #{result} as a normal variable.
</mamut>
I was looking at other tag libraries but couldn’t find anything similar. Or maybe there is?
The use case that motivated me to write this comes from the JBoss.ORG feeds application. There, in several places I have code similar to the following one:
<ui:repeat var="group" value="#{groupsService.all}">
<s:fragment rendered=
"#{groupsService.accFeeds(group).size() > 0}">
(some header)
<ui:repeat var="feed"
value="#{groupsService.accFeeds(group)}">
(...)
</ui:repeat>
</s:fragment>
<ui:repeat>
Of course calling groupsService.acceptedFeeds(group) twice is unnecessarily inefficient. I could move this call to a backing bean, but doing so would only cause me to write some really simple code many times. The version using the let tag calls the method only once:
<ui:repeat var="group" value="#{groupsService.all}">
<mamut:let var="acceptedFeeds"
value="#{groupsService.accFeeds(group)">
<s:fragment rendered="#{accFeeds.size() > 0}">
(some header)
<ui:repeat var="feed" value="#{accFeeds}">
(...)
</ui:repeat>
</s:fragment>
</mamut:let>
<ui:repeat>
If somebody finds this useful, I’ve put the jar here. To use it, just bundle the jar with your application. The namespace for the tag is the following:
xmlns:mamut="http://mamut.net.pl/jsf"
Adam
Post to del.icio.us
The “let” tag enables you to bind the value of any expression to a variable and later reuse it, without recalculating the value. The concept comes of course from functional programming. It is especially useful with Seam’s extended EL.
The usage is really simple:
<mamut:let var="result" value="#{anyElExpression}">
Now you can use #{result} as a normal variable.
</mamut>
I was looking at other tag libraries but couldn’t find anything similar. Or maybe there is?
The use case that motivated me to write this comes from the JBoss.ORG feeds application. There, in several places I have code similar to the following one:
<ui:repeat var="group" value="#{groupsService.all}">
<s:fragment rendered=
"#{groupsService.accFeeds(group).size() > 0}">
(some header)
<ui:repeat var="feed"
value="#{groupsService.accFeeds(group)}">
(...)
</ui:repeat>
</s:fragment>
<ui:repeat>
Of course calling groupsService.acceptedFeeds(group) twice is unnecessarily inefficient. I could move this call to a backing bean, but doing so would only cause me to write some really simple code many times. The version using the let tag calls the method only once:
<ui:repeat var="group" value="#{groupsService.all}">
<mamut:let var="acceptedFeeds"
value="#{groupsService.accFeeds(group)">
<s:fragment rendered="#{accFeeds.size() > 0}">
(some header)
<ui:repeat var="feed" value="#{accFeeds}">
(...)
</ui:repeat>
</s:fragment>
</mamut:let>
<ui:repeat>
If somebody finds this useful, I’ve put the jar here. To use it, just bundle the jar with your application. The namespace for the tag is the following:
xmlns:mamut="http://mamut.net.pl/jsf"
Adam
Post to del.icio.us
The “let” tag enables you to bind the value of any expression to a variable and later reuse it, without recalculating the value. The concept comes of course from functional programming. It is especially useful with Seam’s extended EL.
The usage is really simple:
<mamut:let var="result" value="#{anyElExpression}">
Now you can use #{result} as a normal variable.
</mamut>
I was looking at other tag libraries but couldn’t find anything similar. Or maybe there is?
The use case that motivated me to write this comes from the JBoss.ORG feeds application. There, in several places I have code similar to the following one:
<ui:repeat var="group" value="#{groupsService.all}">
<s:fragment rendered=
"#{groupsService.accFeeds(group).size() > 0}">
(some header)
<ui:repeat var="feed"
value="#{groupsService.accFeeds(group)}">
(...)
</ui:repeat>
</s:fragment>
<ui:repeat>
Of course calling groupsService.acceptedFeeds(group) twice is unnecessarily inefficient. I could move this call to a backing bean, but doing so would only cause me to write some really simple code many times. The version using the let tag calls the method only once:
<ui:repeat var="group" value="#{groupsService.all}">
<mamut:let var="acceptedFeeds"
value="#{groupsService.accFeeds(group)">
<s:fragment rendered="#{accFeeds.size() > 0}">
(some header)
<ui:repeat var="feed" value="#{accFeeds}">
(...)
</ui:repeat>
</s:fragment>
</mamut:let>
<ui:repeat>
If somebody finds this useful, I’ve put the jar here. To use it, just bundle the jar with your application. The namespace for the tag is the following:
xmlns:mamut="http://mamut.net.pl/jsf"
Adam
Post to del.icio.us
The “let” tag enables you to bind the value of any expression to a variable and later reuse it, without recalculating the value. The concept comes of course from functional programming. It is especially useful with Seam’s extended EL.
The usage is really simple:
<mamut:let var="result" value="#{anyElExpression}">
Now you can use #{result} as a normal variable.
</mamut>
I was looking at other tag libraries but couldn’t find anything similar. Or maybe there is?
The use case that motivated me to write this comes from the JBoss.ORG feeds application. There, in several places I have code similar to the following one:
<ui:repeat var="group" value="#{groupsService.all}">
<s:fragment rendered=
"#{groupsService.accFeeds(group).size() > 0}">
(some header)
<ui:repeat var="feed"
value="#{groupsService.accFeeds(group)}">
(...)
</ui:repeat>
</s:fragment>
<ui:repeat>
Of course calling groupsService.acceptedFeeds(group) twice is unnecessarily inefficient. I could move this call to a backing bean, but doing so would only cause me to write some really simple code many times. The version using the let tag calls the method only once:
<ui:repeat var="group" value="#{groupsService.all}">
<mamut:let var="acceptedFeeds"
value="#{groupsService.accFeeds(group)">
<s:fragment rendered="#{accFeeds.size() > 0}">
(some header)
<ui:repeat var="feed" value="#{accFeeds}">
(...)
</ui:repeat>
</s:fragment>
</mamut:let>
<ui:repeat>
If somebody finds this useful, I’ve put the jar here. To use it, just bundle the jar with your application. The namespace for the tag is the following:
xmlns:mamut="http://mamut.net.pl/jsf"
Adam
Post to del.icio.us