-->
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: mapping help on shared PKFK across tables.
PostPosted: Fri Apr 02, 2010 7:26 pm 
Newbie

Joined: Fri Apr 02, 2010 7:06 pm
Posts: 1
Hi Guys,

I have been using NHibernate for about 2 weeks now. For the most part, some Googling and asking around solves my issues.

I am currently running into an issue trying to map the following:
Parent
Child (PK)
GrandChild (PK,FK) <- Child.PK

Child table has a ChildId as primary key, GrandChild uses ChildId as ForeignKey as well as Primary key.

The Child entity looks like this:
public class child{
public virtual SomeOtherObjects Other{get;set;}
public virtual GrandChild GrandChild{get;set;}
}

mapping looks like this:
Child
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="db.dbo">
<class name="Entities.Child, domain" table="Child">

<id name="ChildId" column="ChildId" >
<generator class="native" />
</id>

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

<one-to-one name="GrandChild" class="Entities.GrandChild,domain" cascade="save-update" lazy="false" />

</class>
</hibernate-mapping>

GrandChild
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="db.dbo">
<class name="Entities.GrandChild, domain" table="GrandChild">

<id name="ChildId" column="ChildId" >
<generator class="assigned" />
</id>

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

</class>
</hibernate-mapping>

So basically when I do a SaveOrUpdate(childObj), I get an sql error basically NHibernate wants to insert 0 into the GrandChild. Since Child owns the PK, I want to map it so NHibernate knows to insert the child before it does GrandChild.

Can someone please point me to the right direction?

What got me started looking is I was saving parent and get a transient object not saved exception so I started digging around and decided to attempt to save Child by writing a repository. So right now I think the relationship between Child and GrandChild is what's killing me.


Top
 Profile  
 
 Post subject: Re: mapping help on shared PKFK across tables.
PostPosted: Sat Apr 10, 2010 3:22 pm 
Newbie

Joined: Sat Mar 22, 2008 7:56 am
Posts: 1
generator of child class(foreign class) should be foreign instead of assign.


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.