Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Combination of joined and single_table inheritance  RSS feed

Michael Darsow
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

i would like to combine different inheritance strategies from JPA, but somehow i don't get it to work.

My class hierarchy is like this:

I have a database Table for A, B and C. The Table for class A actually only contains the ID, so that other tables can refer to it.
So i have a JOINED inheritance strategy for the inheritance from A to B and C. The data of D and E should all go into the table of C.

Could anyone help me and tell me how i could realize this please?

My class definitions and annotations are like this, but jpa throws an exception which tells me that class C is not allowed to add an extra column.
I am using OpenJPA.

Thanks a lot!
Bill Gorder
Posts: 1682
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Michael,

Are you using Hibernate as your persistence provider? One of the confusing points is that although JPA allows for a discriminator on the joined inheritance type it does not force the provider to use it. Hibernate does not use it, as a matter of fact it ignores it. So if you are defining a column for the discriminator that may be your issue. In other words you can change


And Hibernate will treat it the same way. It may be the TYPE column you most likely have defined that is causing your issues.

Also I don't see the table E you referred to in your example.

Now to the next point the practice of mixing inheritance types within a single inheritance hierarchy is currently outside the JPA specification. This does not mean that it is not useful but it may not be portable (meaning it is provider specific). So before we can really help further with this we would really know what your persistence provider is.

Also providing a few more details on your table and object structure, the behavior you are seeing and the behavior you want to see would be helpful.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!