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: delete state clean up removed dependencies line 289: null check |
|