I'm working with hibernate and annotations and I'm facing issues annotating my class hierarchy.
My class hierarchy is the following:
ClassA is abstract
ClassB is abstract and extends ClassA
ClassC extends ClassB
Only ClassC can be instantiated and I would like to have:
- fields from ClassA and ClassB in the same table ClassB
- fields from ClassC (not those of ClassA and ClassB) in another table ClassC
The foreign Key in ClassC pointing to ClassB is in column id
of ClassC
Here the code I wrote:
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class ClassA
@Entity
@Table(name = "classB", catalog = "test")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class ClassB extends ClassA
@Entity
@Table(name = "classC", catalog = "test")
@PrimaryKeyJoinColumn(name = "id")
public class ClassC extends ClassB
With this I have the following error messages :
Mixing inheritance strategy in a entity hierarchy is not allowed, ignoring sub strategy in: ClassB
And
Root entity should not hold an PrimaryKeyJoinColum(s), will be ignored
I've read several posts mentioning that multiple inheritance types can't be mixed, some other trying to give warkarounds for some special cases but I didn't findout how to achieve what I would like to have... which is a quite common case I guess.
Is there a nice solution for that ?