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: org.hibernate.PropertyValueException error
PostPosted: Fri Mar 07, 2008 2:39 am 
Newbie

Joined: Fri Mar 07, 2008 2:24 am
Posts: 6
Hi,
I want to save a child record from Child side of the relationship. The reason to save from Child side of relationship is to avoid fetching of all child records. For me, saving from Child side means:
session.save(child);

But while saving i get following error:

rg.hibernate.PropertyValueException: not-null property references a null or transient value: Child._childrenBackref
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)


I have tired in all possbile ways but all in vain. I also referred a lot of posts but that too did not help.

The datastructure used for child records is List. My Parent and Child hbms look as given below:

<class name="Parent" table="PARENT">
<id name="id" type="int" column="id" >
<generator class="assigned"/>
</id>

<property name="name">
<column name="name" />
</property>

<list name="children" lazy="true">
<key column="parentid" not-null="true" />
<list-index column = "parent_child" />
<one-to-many class="Child"/>
</list>


<hibernate-mapping>
<class name="Child" table="CHILD">

<id name="id" type="int" column="ID" >
<generator class="assigned"/>
</id>

<property name="name">
<column name="NAME" />
</property>
<many-to-one name="parentId" column="parentid" class="Parent" insert="false" update="false" not-null="true"/>
</class>
</hibernate-mapping>


The code used to save the child record is:

Parent parent = (Parent)session.load(Parent.class, 2);
Child child = new Child();
child.setId(7);
child.setName("c7");
child.setParentId(parent);
session.save(child);



Though above code works when i also set child in parent object
as given below:
parent.getChildren().add(child)

But that is what i want to avoid as it fetches all children.

Anybody please help !

Thanks in advance !


Top
 Profile  
 
 Post subject: Re: org.hibernate.PropertyValueException error
PostPosted: Fri Mar 07, 2008 10:27 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What does child.setParentId(parent) do? There is no pranetId in the mapping. The problem here is that the parent property is not set so hibernate legitimately complains about it. In addition, you can cache the relationship so you don't have to worry about fetching child records when accessed from parent side.



Farzad-


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.