yes, it is - I've uploaded a development version, in which there is a method:
You can download it here:
Also the ant task should now work when using plain Hibernate.
However, Hibernate really has a lot of features, and it's hard for me to say how it will all work together - so far I've only tested with Hibernate Entity Manager. But underneath it's all the same, so the features supported by Envers in JPA should also work in plain Hibernate.
Anyway, if you'd like to try it, I'm waiting for the feedback :)
Cool! I am thinking of using Hibernate Search and this library together. I presume I will use the same properties in the hibernate session configuration for inserts, updates and deletes? I will definitely give it ago.
sorry what i meant was that can i use:
<property name="hibernate.ejb.event.post-insert" value="org.jboss.envers.event.VersionsEventListener" />
<event type="post-update"/> <listener class="org.hibernate.search.event.FullTextIndexEventListener"/> </event>
yes, you should definitely be able to do that. Just specify the two listeners separated with a comma:
<property name="hibernate.ejb.event.post-insert" value="org.jboss.envers.event.VersionsEventListener,org.hibernate.search.event.FullTextIndexEventListener" />
Or, as you rather won't use persistence.xml:
<event type="post-update"/> <listener class="org.jboss.envers.event.VersionsEventListener" /> <listener class="org.hibernate.search.event.FullTextIndexEventListener"/> </event>
thanks for your quick reply. Will have a go at using it. Sounds and looks good!
I have been trying to get the entity version library to work but unfornately it is not working. I have added the event listeners to the hibernate, and i create an object and save to the database. When I update the object and use
VersionsReader reader = VersionsReaderFactory.get(hibernateTemplate.getSessionFactory().getCurrentSession()); Book versionedBook = reader.find(Book.class, b.getId(), 1);
the following testcase fails:
Book b = new Book(); b.setTitle("Title"); b.setDescription("Description"); b.setCategory("fiction"); b.setIsbn("isbn"); hibernateTemplate.save(b); hibernateTemplate.flush(); Book loadedBook = (Book) hibernateTemplate.get(Book.class, b.getId()); loadedBook.setTitle("another title"); hibernateTemplate.update(loadedBook); hibernateTemplate.flush(); VersionsReader reader = VersionsReaderFactory.get(hibernateTemplate.getSessionFactory().getCurrentSession()); Book versionedBook = reader.find(Book.class, b.getId(), 1); assertEquals("Title", versionedBook.getTitle());
what i get back "another title" instead of "Title" as this was the title set in the first instance.
Any ideas what I'm doing wrong..(I know i'm using Spring...)
I suppose that you're not seeing the correct results as you are doing everything in one session. The current model generates one revision per transaction (as in most cases, the database is in a "consistent" state before and after the transaction, not during it, so that's the state that we want to capture).
If you flush the sesison a couple of times during a transaction, only one change will be saved. Which, depends on the operations.
If you first add, then update the information - then the one revision generated will contain the latest data - because the database was never in a "consistent" state, containing the original data.
If you first update, then delete the information - then the one revision generated will be a "delete" revision.
Hope this helps,
Thanks for your reply. It worked. I created a test to create the book, a separate test to update the book and then final test to load the first version of the book.
I guess my test was 100% accurate. Thanks for help by the way and I'm enjoying using the library. I will be demoing this to the rest of my colleagues at work.
sorry meant to say "my test wasn't 100% accurate"