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.
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.