-->
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.  [ 9 posts ] 
Author Message
 Post subject: Inheritance mapping
PostPosted: Mon Jun 14, 2004 11:02 am 
Newbie

Joined: Wed May 12, 2004 2:57 pm
Posts: 17
Hi, Is inheritance mapping based following db pattern supported in hibernate? Please note that subclass table TBL_USER has it's own primary key, which is different from the one in "table per subclass" strategy.

Table TBL_PERSON
(
ID INT NOT NULL,
FIRST_NAME VARCHAR(50),
LAST_NAME VARCHAR(50),
PRIMARY KEY (ID)
)

Table TBL_USER
(
ID INT NOT NULL,
PERSON_ID INT NOT NULL,
USERNAME VARCHAR(50),
PASSWORD VARCHAR(50),
PRIMARY KEY (ID),
FOREIGN KEY (PERSON_ID) REFERENCES TBL_PERSON(ID)
)

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 11:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No.
This kind of relation is a many-to-one and Hibernate cannot transform it into a class hierarchy

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 2:35 pm 
Newbie

Joined: Wed May 12, 2004 2:57 pm
Posts: 17
Does it matter if PERSON_ID in TBL_PERSON is a UNIQUE constraint?
Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 3:33 pm 
Beginner
Beginner

Joined: Mon Sep 29, 2003 10:32 pm
Posts: 35
Location: Toronto, Ontario
Consider a one-to-one composition relationship between Person and UserAccount. You should favor Composition over Inheritance in OOP.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 5:22 pm 
Newbie

Joined: Wed May 12, 2004 2:57 pm
Posts: 17
javamona wrote:
Consider a one-to-one composition relationship between Person and UserAccount. You should favor Composition over Inheritance in OOP.


Yes, but composition doesn't replace inheritance and Person and User here are just examples.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 5:51 pm 
Beginner
Beginner

Joined: Mon Sep 29, 2003 10:32 pm
Posts: 35
Location: Toronto, Ontario
liushuai wrote:
Does it matter if PERSON_ID in TBL_PERSON is a UNIQUE constraint?
Thank you.


PERSON_ID in TBL_USER? being unique would make it one-to-one.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 6:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
liushuai wrote:
Does it matter if PERSON_ID in TBL_PERSON is a UNIQUE constraint?

Well it won't be enough for Hibernate.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 15, 2004 3:47 pm 
Newbie

Joined: Wed May 12, 2004 2:57 pm
Posts: 17
Thanks to all! I changed the code to adopt "table per subclass" strategy


Top
 Profile  
 
 Post subject: Re: You should favor Composition over Inheritance in OOP
PostPosted: Tue May 02, 2006 6:58 pm 
Newbie

Joined: Tue May 02, 2006 6:54 pm
Posts: 10
Location: Salt Lake City, Utah
javamona wrote:
Consider a one-to-one composition relationship between Person and UserAccount. You should favor Composition over Inheritance in OOP.


You must have missed classes on OOP Analysis and Design. "Is a" implies inheritance. "Has a" implies composition.
The argument that composition should be favored over inheritance is more against inappropriate use of inheritance rather than saying that composition should be used in place of inheritance.


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