Envers version field is nul

I used hibernate-envers version 4.0.1.Final on websphere

So, I annotated my entity by @Audited and version field like
Integer version;

When I change entity, in main table there is inserted new value and version incremented, but in AUD table - in all rows version field still null.

How to fix it?

In fact executed queires

[1/22/19 14:04:51:996 MSK] 00000096 SystemOut O Hibernate: update UserRecord set User=?, version=? where PR_KEY=? and version=?
[1/22/19 14:04:51:998 MSK] 00000096 SystemOut O Hibernate: select hibernate_sequence.nextval from dual
[1/22/19 14:04:52:000 MSK] 00000096 SystemOut O Hibernate: insert into REVINFO (REVTSTMP, REV) values (?, ?)
[1/22/19 14:04:52:002 MSK] 00000096 SystemOut O Hibernate: insert into UserRecord_AUD (REVTYPE, busId, User, UserType, someInfo, PR_KEY, REV) values (?, ?, ?, ?, ?, ?, ?)

Maybe @Naros can help you with this issue.

Hi @Vladislav_Osipenkov

Hibernate Envers has a very specific configuration setting which controls whether or not the optimistic locking field annotated by the @Version annotation is tracked. The name of this configuration property is org.hibernate.envers.do_not_audit_optimistic_locking_field and by default it is true. This means that we do not audit this field. If you enable this to false, then the field will be tracked.

I do want to caution that when the field is tracked, we treat it like any other basic attribute. That means if the original value differs from the value in the persistence context when the persistence operation occurs, that will trigger an audit row insert (even if no other field’s value changed in the entity). This behavior is quite common when using LockModeType#OPTIMISTIC_FORCE_INCREMENT. But if you aren’t doing anything like this, you won’t see any difference in behavior.

Let me know if you run into any other issues.

UPDATED: Fixed typo.


Unfortunately, I changed do_not_audit_optimistic_locking_field to true, but version still null.

I observed any things - in AUD table with version column added REV and REVTYPE columns and they are filled.
In main table(table of entity) in version field version filled and correct value.

My apologies, the default is is true, so set it to false in order to enable the behavior.

@Naros i guess that in 4 version of hibernate-envers there is no functionality for version column, because in AUD table added REV and REV_TYPE columns. In main table of my entity version column is okey, problem is occours only in AUD table

I know the option is there, see the following link:

I would need to check if the functionality is broken in 4.0.1; however if it is you’ll need to upgrade to a later version as we won’t be doing bugfixes to that legacy community version.

@Naros I am using 5.3.7 version. Changing ‘do_not_audit_optimistic_locking_field’ to false doesn’t work.
As per AuditedPropertiesReader, isDoNotAuditOptimisticLockingField’s ‘true’ value is only being checked for version. So, setting this field value to false doesn’t work. Can you please confirm if there is any latest version where this works?