-
1. Re: Hibernate Envers retrieve latest revision number without updating db
adamw Sep 6, 2011 11:02 AM (in response to sanaullah.nazir)To get the current rev number (for the current tx), you have to persist the revision entity, as that's when the DB assigns the revision number.
If you want to know the latest rev number excluding the current tx, just do: select max(re.id) from DefaultRevisionEntity re
Adam
-
2. Re: Hibernate Envers retrieve latest revision number without updating db
mcasperson Jan 20, 2014 11:50 PM (in response to sanaullah.nazir)final AuditReader reader = AuditReaderFactory.get(entityManager);
final Number revision = reader.getRevisionNumberForDate(new Date(Long.MAX_VALUE));
final Date revisionDate = reader.getRevisionDate(revision);
-
3. Re: Hibernate Envers retrieve latest revision number without updating db
andy.newton Apr 6, 2014 11:48 AM (in response to adamw)The behaviour I see is that:
AuditReaderFactory.get(entityManager).getCurrentRevision(DefaultRevisionEntity.class, true);
creates a new revision (with the ID accessible with Number n = revisionEntity.getId();).
However when the current transaction has been committed the actual revision on the relevant update rows in the *_AUD table(s) is > n (n + 1 when no other updates to the database overlap this tx).
So the Id on the returned object from 'getCurrentRevision' isn't the one applied when the current Tx is committed.
For reference, the environment: Hibernate Envers 4.2, Spring 3.2 @Transactional annotated transactions; DB2 9.1.
I've also posted this on SO as a longer question:
Thanks.