-->
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.  [ 1 post ] 
Author Message
 Post subject: Mixed inheritance mapping
PostPosted: Fri Nov 23, 2012 8:43 am 
Newbie

Joined: Wed Sep 19, 2012 8:33 pm
Posts: 4
Hello.
My class hierarchy I want to persist is as follow:
Code:
class A
{
int id;
int a;
int someMethod()
{
return 0;
}
}
class B extends A
{
int b;
@Override
int someMethod()
{
return 1;
}
class C extends B
{
@Override
int someMethod()
{
return 2;
}
}


As you see class A differs from class B with one parameter(int b). Class C differs from class B only with method override, class C does not contain any additional fields. To map it to database tables, I think I need two tables:
- first for the superclass "A"
- second for class B and C
My question is how to map it ? What strategies should I choose ? I consider using this :
- table per class hierarchy ( for class B and C , because these have same fields.
- table per concrete class ( for class A, because it does not have field "int b", which appears in classes B and C.
So the final tables I think should look like :

table_for_class_A:
int id;
int a;

table_for_class_B_and_c:
int id;
int a;
int b;

Is my thinking good ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.