Bytecode enhancement @OneToOne + @LazyToOne not tracked properly when set to NULL

Description

When using bytecode enhancement and @OneToOne with @LazyToOne(value = LazyToOneOption.NO_PROXY) the lazily initialized entities are not tracked properly when set value to null.

The issue happens only when the setter for the property is called before the getter for that property.

the content of the setter is comparing between the old value to the new one , and if they are not equal - the new value is tracked.

if we didn’t fetch the value (by calling the getter) - the original value = NULL, and so if we want to reset the property value by set NULL - the Objects.deepEquals in the setter return true and the property will not be tracked as dirty and will not be updated in DB on the commit .

 

see similar issue:

Environment

None

Activity

Show:
Ayala Goldstein
February 3, 2020, 7:48 AM

I want to fix the issue , I am debating between 2 solutions:

Solution 1: in the setter itself - to check if this property is lazy and the new value = null - if so call the getter method - to fetch the property from DB.

Advantages: this fixing should solve the 2 issues (HHH-13840 and HHH-12772)

Disadvantages: if the entity is detach during the setter - a lazy exception will be thrown and it’s not acceptable to get this exception by calling setter method. in additional it could cause performance issue .

Solution 2: in the setter - to check if the property is lazy and not exist in the interceptor and the new value is null - then track change for this property.

Disadvantages: this fixing will not solve issue HHH-12772, but only HHH-13840.

Advantages: this fixing is not risky and cannot cause any issues.

Hibernate Team , I will be glad to hear your opinion. thanks.

 

 

Assignee

Ayala Goldstein

Reporter

Ayala Goldstein

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