-->
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.  [ 3 posts ] 
Author Message
 Post subject: joined-subclass
PostPosted: Mon Dec 12, 2005 2:03 pm 
Newbie

Joined: Mon Dec 12, 2005 1:54 pm
Posts: 5
Hi,

I have two classes:
- Person is a baseclass.
- Employee is a subclass of Person.

These two correspond with the following database tables in a MSSQL database:
- tblPerson. The primary key is personid, an identity field.
- tblEmployee. The primary key is personid.

When I make a new employee, the following happen:
- A new record in tblPerson is made. The identity primary key generates a new number for the primary key.
- A new record in tblEmployee is made (with the corresponding primary key in tblPerson).

OK now I would like to use an existing Person and associate it to a new employee.

Person person = new Person("MyName")
session.SaveOrUpdate(person)
...
...later
...
Employee employee = new Employee()
...then I don't know, employee.Id must be equal to person.Id.

Is it possible ?

Greets,
Gicks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 4:53 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
Generally, yes, ID of your Employee must be the same as the ID of the Person you are extending.

There is a problem, though: from the database prospective your object will be partially new and partially existing. Its "person" part already exists, while its "employee" part doesn't. I afraid in this case neither ISession.Save, nor ISession.Update could work correctly. Perhaps you will need to create record in tblEmployee table by hands and then Update the object.

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 8:58 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
If a Person can move to an employee, you may think about using roles instead of inheritance...

Anyway, in your case, you can copy all the information from the person the employee and save it (as long as you don't care about not having the original person.Id)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.