-->
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: not-null property references a null or transient value
PostPosted: Tue Nov 02, 2010 1:07 am 
Newbie

Joined: Tue Apr 20, 2010 6:42 am
Posts: 2
I have the following scenario:
class A{
List<B> listB;
C objC;
}
class C{
B objB; //References 'B'
}
class B{
}

Mapping:
<hibernate-mapping>
<class name="A" table="A">
<bag name="listB" table="AB" cascade="all,delete-orphan">
<key column="AId"/>
<many-to-many class="B" column="BId" unique="true"/>
</bag>
<many-to-one name="objC" column="CId" unique="true" not-null="false" cascade="all"/>
</class>
<class name="B" table="B">
</class>
<class name="C" table="C">
<many-to-one name="objB" class="B" column="BId" not-null="true" unique="true" />
</class>
</hibernate-mapping>

Now I have following code.
A objA = new A();
B objB = new B();
C objC = new C();
objA.listB.add(objB);
objA.objC = objC;
objC.objB = objB;
save(objA);// Get not-null property references a null or transient value: C.objB

Why am I getting this exception? Why can't hibernate store both objB and objC together?


Top
 Profile  
 
 Post subject: Re: not-null property references a null or transient value
PostPosted: Tue Nov 02, 2010 4:44 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
Specify "cascade" everywhere or save objects manually in reverse order.


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.