-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate nullability check on delete?
PostPosted: Mon Mar 26, 2007 10:10 am 
Newbie

Joined: Fri Mar 23, 2007 2:23 pm
Posts: 1
Hibernate version: 3.0.5

I am having a problem with Hibernate caring about nullability for objects it is about to delete.
I am having the following problem.

1) Calling SaveOrUpdate on an Object X.
2) Hibernate traverses my Object X graph
3) Hibernate find Object A (which was deleted) and proceeds to delete the object and set the reference to NULL
4) Hibernate then finds Object B which has a reference to the deleted object A and itself is also being deleted. The reference to A is mapped as not-null="true"
5) The following exception is thrown

org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: B.A; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: B.A
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: B.A
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:250)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:141)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:775)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:758)
at org.hibernate.engine.Cascade.deleteOrphans(Cascade.java:355)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:324)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)


If I change the mapping to not-null="false" everything work perfectly.

Can anyone explain this to me?

Mike


Top
 Profile  
 
 Post subject: I have the same problem
PostPosted: Mon Mar 31, 2008 10:31 am 
Beginner
Beginner

Joined: Tue Jan 08, 2008 2:15 pm
Posts: 22
I have a complex object graph in which the root entity has a list of all VersionRecords (representing all the updates it went through during its life). However, some of these VersionRecord instances are shared with objects in the object tree so each of them points to its current VersionRecord, which is always in the root entity list as well.

So, stripped down to its minimum, I have:

Object A holds a list of VersionRecord and an Object B containing only a single instance in our case

Object B points to a VersionRecord too (an instance shared with A)

Now, when we delete the root (A): Hibernate deletes the shared VersionRecord in its list as part of the cascade delete on Object A, but then, when cascade deleting B, it sees the shared VersionRecord has been deleted (now transient) and nullifies the reference to that instance from B's property, which then fails to pass the checks for nullability since that property is NOT nullable in B.

from DefaultDeleteEventListener.deleteEntity method:
Code:
...
// MyComment: this nullifies every property pointing to deleted (now transient) instances (for ManyToOne only?)
new ForeignKeys.Nullifier( entity, true, false, session ).nullifyTransientReferences( entityEntry.getDeletedState(), propTypes );

// MyComment: then this checks not-null constraints from the metadata against nulled properties! Why on delete?
new Nullability( session ).checkNullability( entityEntry.getDeletedState(), persister, true );

...


Why nullify references to transient instances (just deleted or not) from an object that is going to be deleted?


Top
 Profile  
 
 Post subject: Hibernate bug
PostPosted: Fri Jul 18, 2008 4:40 pm 
Newbie

Joined: Wed Nov 02, 2005 5:20 pm
Posts: 9
This is caused by a Hibernate bug:
http://opensource.atlassian.com/project ... e/HHH-2792


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.