We're updating the issue view to help you get more done. 

Incorrect update occurs when updating a detached object with empty component and @SelectBeforeUpdate

Description

Hibernate updates objects incorrectly on the following condition:

  • the entity has @SelectBeforeUpdate and @Embedded property.

  • there is an object whose properties in the embedded component are all null.

  • the object is retrieved and detached.

  • the object is either unchanged, null component set to empty component, or empty component set to null

  • the object is saved with session.update(obj)
    Then actual database update should not occur, but it does.

Note that with the introduction of hibernate.create_empty_composites.enabled setting,
null and empty component should be treated the same in dirty checking.
This issue exists for both cases: i.e. hibernate.create_empty_composites.enabled=true/false.
(ref: http://in.relation.to/2016/02/10/hibernate-orm-510-final-release/#embeddables-and-all-null-column-values)

Note that this issue does not occur if the same updates are done within a session.
Only occurs when updating detached objects.

Note, this bug has a serious consequence of updating audit information incorrectly.
The issue probably exists in hibernate-core, but hibernate-envers is also affected.

Maybe org.hibernate.type.CompositeType.isModified is to be fixed?

Attached the test case. Please check. Thank you.

Environment

None

Status

Assignee

Chris Cranford

Reporter

Taro App

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Fix versions

Affects versions

5.1.3
5.2.7
5.2.4
5.2.5

Priority

Major