Hi All,
it seems that I don't see the wood for the trees. Maybe one of you can help.
I' ll try so simplify my use case to two tables:
PARENT Table:
ID,parentData1,...
CHILD Table
ID,parentID,childData1,...
parentID is FK of PARENT.ID
Now the classes:
class Parent {
ID
ISet<Child> Children
parentData1
....
}
class Child {
ID
Parent P
childData1
}
-----------------------------------------------------------------
The first issue I have is that I only need to have the member P because
NHibernate needs it for the association.
In my application the child does not need to know about the parent.
The second issue is that it doesn't suffice to do some thing like:
Child c = new Child();
Parent p = (Parent) sess.Load(typeof(Parent ), id);
p.Children.Add(c);
sess.Flush();
because then "c" is not persisted.
What I have to do is
Child c = new Child();
Parent p = (Parent) sess.Load(typeof(Parent ), id);
p.Children.Add(c);
c.P = p
session.Save(c);
sess.Flush();
Why is this necessary since the persistence layer should know what
Parent to use?
When having more complex structures this becomes an enormous task.
Can someone explain me I am overlooking something really obvious?
Kindest regards,
Victor
------------------------------------------------------------------------------------------------
<class name="Parent" table="T_PARENT" dynamic-update="true">
<!-- properties used by NHibernate -->
<id name="Key" column="F_KEY">
<generator class="native" />
</id>
<!-- properties used for business logic -->
<set name="Children" inverse="true" cascade="all" >
<key on-delete="cascade" foreign-key="FK_PARENT_CHILD">
<column name="F_CHILD" not-null="true"/>
</key>
<one-to-many class="Child" />
</set>
</class>
<class name="Child" table="T_CHILD" dynamic-update="true">
<!-- properties used by NHibernate -->
<id name="Key" column="F_KEY">
<generator class="native" />
</id>
<!-- properties used for application logic -->
<many-to-one
name="P"
class="Parent"
column="F_PARENT"
foreign-key="FK_CHILD_PARENT"
not-null="true"
cascade="all"
/>
</class>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---