Today I faced an interesting issue. I've been having an inheritance hierarchy with Hibernate JPA, with SINGLE_TABLE
strategy. Later, I added a superclass to the hierarchy, which defined TABLE_PER_CLASS
strategy. The result was that the whole hierarchy stared behaving as TABLE_PER_CLASS
. This, of course, seems fair, if we read the @Inheriatance
javadoc:
Defines the inheritance strategy to be used for an entity class hierarchy. It is specified on the entity class that is the root of the entity class hierarchy.
Hibernate docs, however, say that:
It is possible to use different mapping strategies for different branches of the same inheritance hierarchy
And continues on the exemptions from this statement. This is done via XML configuration.
So, finally, my question is - is there a way (a hibernate property, perhaps) to enable the aforementioned xml behaviour via annotations, and using EntityManager
.