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

Cannot delete updated entity if its original ManyToOne relation was deleted

Description

Scenario:
1) Disable auto flush
2) Fetch 2 entity (ex. Person A, B) + some dependent (ex. Address AddrA for Person A)
3) Reassign Address AddrA from A Person to B Person
4) Delete Person A
5) Delete AddrA
___
result is exception org.hibernate.PropertyValueException: not-null property references a null or transient value,

For some reason hibernate realize null check before deleting entity and do it base on loadedState. Loaded state contains reference to original object which was scheduled to delete. Null check consider removed ManyToOne relations as null and throws exception.

Expected behavior: allow to delete entity, use actual values if null check is needed.

Acutally problem is in method org.hibernate.event.internal.DefaultDeleteEventListener#deleteEntity
line 263: hibernate decide to use getLoadedState() instead of actual state.
line 271: clean up references to removed dependencies
line 289: null check

Environment

None

Status

Assignee

Unassigned

Reporter

Mateusz Pszczolka

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.4.2

Priority

Major