This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.