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: Simple one-to-many relationship
PostPosted: Fri Feb 26, 2010 4:24 pm 
Newbie

Joined: Fri Feb 26, 2010 4:08 pm
Posts: 1
Hello: I am new to nhibernate and having been having issues modelling a simple relationship of parent child.
Parent table: parent_id [ Guid ]
Child table: child_id[guid], parent_id [ FK from Parent Table, Not null, Guid ]
Parent has a "list" of child objects [0...n]

The Parent Object references a HashedSet<Child>, however when I try to save

{"Cannot insert the value NULL into column 'parent_id', table 'tblChild'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."}

I don't have any property in Child object referring the parent back, since the child shouldn't exist on its own.

Any pointers are much appreciated.

-------------snip----------------snip---------------snip-----------------
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="mynamespace" assembly="mynamespace">
<class name="mynamespace.parent" table="tblParent">
<id name="ParentId column="parent_id">
<generator class="guid" />
</id>
<set name="Children" table="tblChild" lazy="true">
<key column="parent_id" not-null="true" />
<one-to-many class="Child" />
</set>
</class>
<class name="mynamespace.Child" table="tblChild">
<id name="ChildId" column="child_id">
<generator class="guid" />
</id>
<many-to-one name="ParentId" class="Parent" column="parent_id" not-null="true" />
</class>
</hibernate-mapping>
-----------------------------------------------------------------------------------------------


Top
 Profile  
 
 Post subject: Re: Simple one-to-many relationship
PostPosted: Mon Mar 01, 2010 3:54 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Seems that you were intended to map a bidirectional association but you forget to specify the inverse attribute.


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.