Hi all,
I have a hibernate model with two classes, let's say A and B. B has a many-to-one reference to A.
I query a single A and a single B object. These are detached from the Session and they get processed somewhere/used else. The B.A property is a lazy proxy. Sometime later A and B both need to be deleted. I create a new Session and call .delete(A) and .delete(B).
Deleting A is ok but then deleting B causes the following exception
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.xxx.hibernate.objects.B.A
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95) [hibernate3.jar:na]
at org.hibernate.event.def.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:272) [hibernate3.jar:na]
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:163) [hibernate3.jar:na]
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74) [hibernate3.jar:na]
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:794) [hibernate3.jar:na]
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:772) [hibernate3.jar:na]
Diggin in the code it looks as tho during the deletion a nullability check is done, and because A was deleted first, deletion of B fails the null check. It thinks it's A reference is "null" even tho the B object I pass in it is set to not-null. Looks like it does some lookup in the interal Session state and finds the deleted A instance.
Anyone know how I can work round this? I would prefer not to rely on the ordering of the deletion if possible, unless deleting A before B is fundamentally wrong for some reason I'm not seeing.
I'm also not entirely sure why a null check is required on a delete TBH.
Appreciate any suggestions.