Hello,
I'm just starting with Hibernate and I've got some troubles with mapping file writing.
There are three classes : Student, Book and Person.
A Student inherits from Person and has an association "HisBooks" which return Student's books collection.
This is my mapping file :
<class name="WindowsApplication2.Person, WindowsApplication2" table="Person">
<id name="ID" type="Int32" column="IDPerson">
<generator class="identity"></generator>
</id>
<property name="FirstName" column="firstname" type="String"></property>
<property name="LastName" column="lastname" type="String"></property>
<property name="Age" column="age" type="Int32"></property>
<joined-subclass name="WindowsApplication2.Student, WindowsApplication2" table="Student">
<key column="IDPerson" foreign-key="IDStudent"></key>
<property name="Code" column="code" type="String"></property>
<set lazy="true" name="HisBooks">
<key column="IDStudent" foreign-key="IDStudent"></key>
<one-to-many class="WindowsApplication2.Book, WindowsApplication2"></one-to-many>
</set>
</joined-subclass>
</class>
<class name="WindowsApplication2.Book, WindowsApplication2" table="Book">
<id name="ID" type="Int32" column="IDBook">
<generator class="identity"></generator>
</id>
<property name="Name" column="name" type="String"></property>
<property name="Code" column="code" type="Int32"></property>
</class>
As you can see, I'm using "one table per class" strategy.
Person table contents : IDPerson, firstname, lastname, age
Student table contents: IDStudent, code , IDPerson
Book table contents : IDBook, code, IDStudent
The problem comes when I try to save a Student, because Hibernate uses the Person ID in the Book table, and not the dynamically generated Student ID (but I want to split both !)
So, how can I do, to split Person ID and Student ID, so that when I save a student, the linked books take the Student ID and not the inherited Person ID (it's clear ? lol)
Thanks
|