Hi,
I'm new to NHibernate and currently using NHibernate 1.2.0.GA for a project.
I got a problem with my mapping (I think).
This is the situation...
Database
Persons
personID [PK]
name
sname
Students
studentID [PK]
personID [FK:Persons.personID]
Profs
profID [PK]
personID [FK:Persons.personID]
Classes
classID [PK]
className
StudentInClass
classID [FK:Classes.classID]
studID [FK:Students.studentID]
C#
Person, Student, Prof just got the same data members as in the database.
Class has a collection (List<Student> students) that holds all the student attending a class.
Map
Person
<class name="Person" table="Persons" lazy="false">
<id name="PersonID" column="personID" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="name" type="String" length="50" />
<property name="SName" column="sname" type="String" length="15" />
</class>
Student
<joined-subclass name="Student" table="Students" lazy="false" extends="Person">
<key column="personID" />
<property name="StudID" column="studID" type="Int32" />
</joined-subclass>
Prof
<joined-subclass name="Prof" table="Profs" lazy="false" extends="Person">
<key column="personID" />
<property name="ProfID" column="profID" type="Int32" />
</joined-subclass>
Class
<class name="Class" table="Classes" lazy="false">
<id name="ClassID" column="classID" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<property name="ClassName" column="className" type="String" length="5" />
<bag name="Students" table="StudentInClass" lazy="false">
<key column="classID"/>
<many-to-many class="Student" column="studID" />
</bag>
</class>
Problem
The problem is, when i ask for all the students I works fine. It links all the personID's in the student table to the right personID
in the person table.
However when i ask for all the classes and by this also asking for the students in those classes this get mixed up. It gets all the
classes and then the students in those classes (by the studID in StudenInClass table) then it links the students to the person
table. And this is where it fixes up. When linking to the person table it uses the studID to get record in the person table. It should
use the personID linked to the studentID in the student table.
Exp:
Person
[PersonID][Name][SName]
1 Do Jhone
2 Do Bob
3 Do Marc
4 Do Simon
Student
[StudID][PersonID]
1 2
2 4
3 1
Class
[ClassID][ClassName]
1 NHibernate Course
2 C# Course
StudentInClass
[StudID][ClassID]
1 1
1 2
2 1
3 1
The result should be:
NHibernate Course
=> Do Bob (studID 1, personID 2)
=> Do Simon (studID 2, personID 4)
=> Do Jhone (studID 3, personID 1)
C# Course
=> Do Bob (studID 1, personID 2)
But it's
NHibernate Course
=> Do Jhone (studID 1, personID 1)
=> Do Bob (studID 2, personID 2)
=> Do Marc (studID 3, personID 3)
C# Course
=> Do Jhone (studID 1, personID 1)
Can some1 help me with this problem?
Thanks in advanced
// Snelle Kenny
|