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.  [ 1 post ] 
Author Message
 Post subject: why Child class doesnt get data of Parent table after insert
PostPosted: Wed Oct 15, 2008 4:12 am 
Newbie

Joined: Mon Sep 29, 2008 12:48 am
Posts: 1
I have 2 class: Parent, Child
Parent uses one-to-many to call a Child bag
Child uses many-to-one to call a Parent infor.

I write code in C#, .NET 2005.

When data loaded, it works success, both Parent and Child get data together is correct.
But when I insert a Child, this Child cannot get infor of Parent.
Here is a sample :
1. Choose Parent with ID = 2, Name = 'Animal'
2. Input Child's Name with Name = 'Dog'
3. Click Save. (success, data inserted into database)
4. Get data use List Object (List<Child>) listChild
5. Get Child just insert : Child [info] = listChild[1];
6. [info] has ParentID = 2 but InfoParent class is null


When I stop program and start again, it will works normal.
I don't understand what is nHibernate doing?

Can you show me an idea to solve this problem?

This is my code :
Class Parent :
Quote:

public class Parent : DomainObject<Int32>
{
public Parent()
{
}

private string _Name;

public virtual string Name
{
get { return _Name; }
set { _Name = value; }
}

private IList<Child> _ListChild;
public virtual IList<Child> ListChild
{
get { return _ListChild; }
set { _ListChild = value; }
}

Quote:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="RedSea.CMS.Model" namespace="RedSea.CMS.Model">
<class name="Parent" table="Parent" >
<id name="ID" type="System.Int32" column="ParentID" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="Name" type="System.String" not-null="false" />
<bag name="ListChild">
<key column="ParentID" />
<one-to-many class="Child" />
</bag>
</class>
</hibernate-mapping>


Class Child :
Quote:
[Serializable]
public class Child : DomainObject<Int32>
{
public Child()
{
}

private string _Name;

public virtual string Name
{
get { return _Name; }
set { _Name = value; }
}

private int _ParentID;

public virtual int ParentID
{
get { return _ParentID; }
set { _ParentID = value; }
}

private Parent _InfoParent;
public virtual Parent InfoParent
{
get { return _InfoParent; }
set { _InfoParent = value; }
}
}


Quote:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="RedSea.CMS.Model" namespace="RedSea.CMS.Model">
<class name="Child" table="Child" >
<id name="ID" type="System.Int32" column="ChildID">
<generator class="identity" />
</id>
<property name="ParentID" column="ParentID" type="System.Int32" not-null="false" />
<property name="Name" column="Name" type="System.String" not-null="false" />
<many-to-one name="InfoParent" class="Parent" column="ParentID" update="false" insert="false"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.