Reputation: 542
I am migrating a java application from Spring Boot 1.5 to Spring Boot 2.2.3 and this involves upgrading Hibernate/Envers to 5.4.10.Final.
The existing code calls AuditReader#getCurrentRevision(Class revisionEntityClass, boolean persist) which is deprecated and the JavaDocs state to use RevisionListener but this does not do the same thing as we need to fetch the revision that will be created when the existing transaction commits. The getCurrentRevision method gave us that functionality but the RevisionListener is not invoked until after our code needs the revision number and also the revisionEntity passed to the RevisionListener#newRevision method does not yet have its id set. RevisionListener seems to be targetted more towards setting additional information on the revision entity rather than obtaining information from it.
How can I obtain the revision that will be created as part of the current transaction?
Thanks
Upvotes: 2
Views: 573
Reputation: 542
To add some context ... we needed to store the current revision on an entity representing an event so that the event could be replayed at end of day and access the state of an account as it was at the time of the event.
In our previous (Spring Boot 1.5) version of the application we did not audit the event entities because we had no need to.
To work around the functionality being deprecated and thus marked for removal we simply started auditing the event entity. This way we are able to access the revision of the event entity insert at the time that we are processing the event rather than when we insert it and that gives us the revision for the state of the account at the time the event was raised.
Not an answer as such to my original question but a clean solution to the functional requirement.
Upvotes: 0