Let me explain the problem I have:
Code:
public class Z {
protected Z(); // protected constructor.
public boolean active;
}
public class A extends Z {
public long id;
public String name;
}
public class B extends Z {
public long id;
public String color;
}
Here is the hibernate mapping I try to do:
class Z do not need a real table, constructor is protected, so no self instance of Z can exist. Those class simply provide common features to subclass.
In fact, I need to have only two database tables :
Code:
TABLE_A
- id
- name
- active <= from Z
TABLE_B
- id
- color
- active <= from Z
That all, But I cannot find how to do those map in hibernate.
It seems that is not possible to do the trick like this.
With table-per-hierarchy (<subclass>) strategie mapping we have one big table with discriminator. But this way introduce problem for not null field constraints on subclass.
With table-per-subclass (<joined-subclass>) strategie mapping we will have three databses tables with one-to-one relation between A,Z and B,Z.
(that not what I want for performance reasons)
With table-per-concrete-class (<any>) strategie mapping, it seems that we have to include all Z persistant fields inside A and B. So we must map the 'active' field in all subclass. (I want to avoid to repeat the 'active' field in each subclass)
Is there a way to do the trick without explicitly map the 'acitve' field inside each subclass ? The goal is to provide the 'active' persistant field inside Z class and never have to make map each time we create a new subclass.
Thanks in advance for all your comments.