I'm migrating several code bases to use Hibernate 5.4.x instead of Hibernate 5.2.x.
For an abstract base class I use
@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractPersistentJPAObject extends AbstractPersistentObject {
// some properties
}
However, the ORM complains about this with the error message
An entity cannot be annotated with both
@Inheritance
and@MappedSuperclass
This was not a problem with Hibernate <= 5.2.x and now I wonder why this should not be allowed any more.
Any solid answers welcome.
My answers are given below:
The mapping is incorrect according to the JPA 2.2 specification, @MappedSuperclass
and @Inheritance
cannot be used together. It seems, the mapping above was tolerated in earlier Hibernate releases. However, this support seems to be removed in Hibernate 5.4.x.
To solve the issue in this specific scenario described above, you can replace @MappedSuperclass
with @Entity
and it should work fine.
There is also a similar question in the Hibernate forum.
You can also check HHH-13217, in which Gail Badner & Vlad Mihalcea (both Hibernate Developers) are discussing about this issue.
In the next upcoming release 5.4.2, @Inheritence
will be ignored, if it is used alongside @MappedSuperclass
(see the related PR on Github).