File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Combination of joined and single_table inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Combination of joined and single_table inheritance" Watch "Combination of joined and single_table inheritance" New topic

Combination of joined and single_table inheritance

Michael Darsow

Joined: Mar 11, 2012
Posts: 4
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

Joined: Mar 07, 2010
Posts: 1682

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.

[How To Ask Questions][Read before you PM me]
I agree. Here's the link:
subject: Combination of joined and single_table inheritance
It's not a secret anymore!