Setting a lazy property to null missed by bytecode assisted dirty check

Description

Given an entity with a lazy property, and using bytecode enhancement with enableLazyInitialization and enableLazyInitialization, setting the property to null will not trigger database update on flush.

This does not happen when bytecode enhancement is off, or if the field is set to a non-null value just prior to setting it to null.

Digging deeper, the pseudo code of the enhanced setter is:

void $$_hibernate_write_property(value) {
if (!Objects.deepEquals(this.field, value)) {
this.trackField($$_hibernate_trackChange)
}
....
}

I think the problem is that the enhanced setter bypass field lazy initialisation for comparison, which is generally fine unless the target value is null (or 0, or whatever the default is)

hibernate version: 5.4.21

Environment

None

Assignee

Unassigned

Reporter

Ludovic Pollet

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure