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 ?