# Envers version field is nul

**URL:** <https://discourse.hibernate.org/t/envers-version-field-is-nul/2113>\
**Category:** Hibernate ORM\
**Created:** [January 22, 2019, 10:36am UTC](https://discourse.hibernate.org/t/envers-version-field-is-nul/2113 "2019-01-22T10:36:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladislav\_Osipenkov](https://avatars.discourse-cdn.com/v4/letter/v/d78d45/32.png) [@Vladislav\_Osipenkov](https://discourse.hibernate.org/u/Vladislav_Osipenkov)\
**Post date:** [January 22, 2019, 10:36am UTC](https://discourse.hibernate.org/t/envers-version-field-is-nul/2113/1 "2019-01-22T10:36:34Z")

</div>

I used hibernate-envers version 4.0.1.Final on websphere 8.5.5.13

So, I annotated my entity by @Audited and version field like  
@Version  
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 (?, ?, ?, ?, ?, ?, ?)

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [January 22, 2019, 1:23pm UTC](https://discourse.hibernate.org/t/envers-version-field-is-nul/2113/2 "2019-01-22T13:23:19Z")

</div>

Maybe @Naros can help you with this issue.

---

<div class="post-metadata">

**Author:** ![Naros](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/naros/32/19_2.png) [@Naros](https://discourse.hibernate.org/u/Naros)\
**Post date:** [January 22, 2019, 4:52pm UTC](https://discourse.hibernate.org/t/envers-version-field-is-nul/2113/3 "2019-01-22T16:52:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Vladislav\_Osipenkov](https://avatars.discourse-cdn.com/v4/letter/v/d78d45/32.png) [@Vladislav\_Osipenkov](https://discourse.hibernate.org/u/Vladislav_Osipenkov)\
**Post date:** [January 23, 2019, 8:32am UTC](https://discourse.hibernate.org/t/envers-version-field-is-nul/2113/4 "2019-01-23T08:32:02Z")

</div>

@Naros

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.

---

<div class="post-metadata">

**Author:** ![Naros](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/naros/32/19_2.png) [@Naros](https://discourse.hibernate.org/u/Naros)\
**Post date:** [January 23, 2019, 8:36am UTC](https://discourse.hibernate.org/t/envers-version-field-is-nul/2113/5 "2019-01-23T08:36:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Vladislav\_Osipenkov](https://avatars.discourse-cdn.com/v4/letter/v/d78d45/32.png) [@Vladislav\_Osipenkov](https://discourse.hibernate.org/u/Vladislav_Osipenkov)\
**Post date:** [January 23, 2019, 9:32am UTC](https://discourse.hibernate.org/t/envers-version-field-is-nul/2113/6 "2019-01-23T09:32:48Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![Naros](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/naros/32/19_2.png) [@Naros](https://discourse.hibernate.org/u/Naros)\
**Post date:** [January 23, 2019, 2:27pm UTC](https://discourse.hibernate.org/t/envers-version-field-is-nul/2113/7 "2019-01-23T14:27:55Z")

</div>

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

> <https://github.com/hibernate/hibernate-orm/blob/4.0/hibernate-envers/src/main/java/org/hibernate/envers/configuration/GlobalConfiguration.java#L74>

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.

---

<div class="post-metadata">

**Author:** ![poonam\_bansal](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/poonam_bansal/32/1026_2.png) [@poonam\_bansal](https://discourse.hibernate.org/u/poonam_bansal)\
**Post date:** [April 15, 2020, 7:36am UTC](https://discourse.hibernate.org/t/envers-version-field-is-nul/2113/9 "2020-04-15T07:36:56Z")

</div>

@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?
