-->
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.  [ 2 posts ] 
Author Message
 Post subject: two cascading paths - null or transient value exception
PostPosted: Thu Jan 22, 2009 3:10 pm 
Newbie

Joined: Thu Jan 22, 2009 2:24 pm
Posts: 2
Should I expect some intelligence from Hibernate when an object can be reached through two paths: an all-cascading and a non-cascading association path? I would expect that Hibernate notices that the object should be persisted, but this doesn't seem to be the case. I also didn't find any guarantee in the EJB3.0 specification.

Here is an example:
I have a parent object which refers to two children. The parent object has CascadeType.ALL on both child relation. One of the children refers to the other child.
In a transaction I retrieve the parent from the database and create two children and set all three relations. When I flush the session I receive org.hibernate.PropertyValueException "not-null property references a null or transient value" on the child referring to the other child. If I also set CascadeType.ALL on the latter association then Hibernate saves all three objects correctly.

Hibernate version: 3.2.2.ga and 3.3.1.GA

Mapping documents:
Mapping of the parent object:
@OneToOne(cascade = CascadeType.ALL)
public Payment payment;

@OneToOne(cascade = CascadeType.ALL)
public Invoice invoice;

Mapping of the child which refers to another child:
@OneToOne(optional = false)
public Payment payment;


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 5:33 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I guess this happens because of the order the cascades are processed. I don't know if it is deterministic or if the order can be controlled in some way.

In any case, my theory is that, when saving the parent object one of the children has to be processed first. In your case it seems like this happens to be the child that also has a reference to the other child. And since this child hasn't been processed yet you get the exception. If you somehow can force Hibernate to process the other child first I think everything should work.

The thing is that I don't know if it is possible to control the order the cascades are processed.... but I just found this in Hibernate JIRA http://opensource.atlassian.com/project ... e/HHH-3229
and maybe it has been fixed in the next release.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.