Hello.
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:
@MappedSuperclass
@Inheritance(strategy = InheritanceType.JOINED)
@Viewable
public abstract class BaseEntity implements Constants
{
public final static String PROPERTY_ID = "id";
@Id
@Access(AccessType.PROPERTY)
// 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)
{
this.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(AnnotationBinder.java:539)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:250)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:231)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:274)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:84)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:474)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:615)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741)
... 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,
Sebastian