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.  [ 8 posts ] 
Author Message
 Post subject: Mapping confusion
PostPosted: Thu Aug 24, 2006 2:13 am 
Newbie

Joined: Thu Aug 24, 2006 2:10 am
Posts: 3
I have 2 tables : Persons and Emplyees.

Persons:

PersonID PK
Name
DateofBirth

Employees:

EmployeeID PK
PersonID FK
Job


Now, I want to have an object in the code which includes properties like person name, job etc. (this is like a join in SQL)

How should I do the mapping, I don't quite get it.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 5:38 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
The more general approach is to model the employment as a qualified association to an Employer class, in this case that one person can be employed by several Employers. This means that Person and Employment will be separate classes.

Implementation: Person -one-to-many- Employment -many-to-one- Employer.


Cheers,
Radu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 6:13 am 
Newbie

Joined: Thu Aug 24, 2006 2:10 am
Posts: 3
Actually its not employer, but employee.

What I want, is to have Employer object in the code, so i can get the names and stufff from employer object(names are stored in Persons table in DB not in Employee table.).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 6:36 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
if you are sure that between Persons and Employee you have a one-to-one relationship (and this won't change in the future) you can map a Person object on Persons table and have Employee object inherit from Person and map it as a joined-subclass.

radu


Top
 Profile  
 
 Post subject: re: Mapping Confusion
PostPosted: Thu Aug 24, 2006 8:51 am 
Newbie

Joined: Wed Aug 16, 2006 2:49 am
Posts: 14
[deleted]


Last edited by kokoness on Thu Aug 24, 2006 8:54 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: re: Mapping Confusion
PostPosted: Thu Aug 24, 2006 8:52 am 
Newbie

Joined: Wed Aug 16, 2006 2:49 am
Posts: 14
Try to take a look at this one

http://nhibernate.sourceforge.net/nh-do ... ation.html

search for one-to-one in the table of contents


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 9:20 am 
Newbie

Joined: Thu Aug 24, 2006 2:10 am
Posts: 3
Well, actually one person can act in many employee roles.

One employee is a certain person, but one person could have several employee roles.


Top
 Profile  
 
 Post subject: Re: Confusion Mapping
PostPosted: Thu Aug 24, 2006 8:40 pm 
Newbie

Joined: Wed Aug 16, 2006 2:49 am
Posts: 14
"Well, actually one person can act in many employee roles.

One employee is a certain person, but one person could have several employee roles."

Oops, my fault. He can instead take a look at the one-to-many, many-to-one, or whatever association that suits his requirements.


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