1

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 ?

  • http://stackoverflow.com/questions/3915026/how-to-mix-inheritance-strategies-with-jpa-annotations-and-hibernate – Ashish Jagtap Dec 10 '13 at 08:42
  • I've read this post before, and it is not definitly not answering my question. I really need to have these 3 levels: ClassA definied with TABLE_PER_CLASS startegy and ClassB extending ClassA with JOINED startegy. The mentioned post is not taking this case into account :/ – user3084149 Dec 10 '13 at 11:37

0 Answers0