-->
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: NHibernate and inheritance
PostPosted: Wed Mar 08, 2006 5:20 pm 
Beginner
Beginner

Joined: Tue Mar 07, 2006 8:50 am
Posts: 20
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 5:46 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
This seems like an interesting issue, but... well, why do you need to do this?


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.