Can no longer use @MappedSuperclass and @Inheritance annotations in Hibernate 5.4


I just updated our software from hibernate orm 5.2.12 to 5.4.0 which was as easy as changing the dependency in the project. But after several tries I still encounter a problem which seems to be related to our inheritance strategy.
We have a simple POJO that we call BaseEntity. This class only defines an id property along with the generator strategy. Since we want ALL entities share the same type of id, we made this class a MappedSuperclass. We also wanted to use the JOINED InheritanceType for the whole entity hierarchy. Thus the mapping looks like this:

@Inheritance(strategy = InheritanceType.JOINED)
public abstract class BaseEntity implements Constants
	public final static String PROPERTY_ID = "id";

	// 128bit UUID => 16 Byte => as Hex-String 32 chars + four '-' chars
	@Column(name = PROPERTY_ID, length = 36, nullable = false)
	private String id = IdGenerator.generateId();

	public void setId(final String id)
	{ = id;

	public String getId()
		return id;
// Some more stuff here (equals, hashCode and the like

Till the upgrade this mapping worked like a charm for the past 6 years now. But with 5.4 I encounter the following exception when starting up the application:

org.hibernate.AnnotationException: An entity cannot be annotated with both @Inheritance and @MappedSuperclass: eu.inform.model.entities.BaseEntity
	at org.hibernate.cfg.AnnotationBinder.bindClass(
	at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(
	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(
	at org.hibernate.cfg.Configuration.buildSessionFactory(
	at org.hibernate.cfg.Configuration.buildSessionFactory(
	at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(
	at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(
	... 27 more

Is this by design, by decision or only mistaken? What can we do to enforce our database definition? We do not want a central BaseEntity-table with millions of entries.

Kind regards,


The mapping is wrong according to the JPA specs. Remove @MappedSuperclass and it should work just fine.

1 Like

Isn’t this going to materialize a BaseEntity table in the database that is joined by any subclass when selecting it? If so this is not what we want to achieve.
I worked around it and moved the @Inheritance annotation to any of the subclasses which seems to work properly.

Yes, that’s right. You should use @Inheritance if you want to materialize the Java-based inheritance tree into the DB. If you don’t want that, you use @MappedSuperclass and you move the @Inheritance annotation to the first class down the inheritance tree that will be materialized in the DB.

I worked around it and moved the @Inheritance annotation to any of the subclasses which seems to work properly.

That’s great.


Than you may closed this issue.
I summarise that my previous configuration was not valid according to JPA but supported by later hibernate releases. This support stopped in 5.4.0.Final why I had to change my annotation-driven configuration.

Thank you very much.