Define a OneToMany association in a MappedSuperclass when using Hibernate
Issue
- A
MappedSuperclass(e.g.Employee) is defined as the parent of multiple subclasses. - The inheritance hierarchy rooted at the
MappedSuperclasshas aOneToManyassociation with a list/set of related entities (e.g.Task). -
If
mappedByis used in theOneToManydeclaration and theManyToOnereferences theMappedSuperclassan exception is raised during deployment (whereEmployeeis theMappedSuperclassreferenced by aManyToOneinTask):org.hibernate.AnnotationException: @OneToOne or @ManyToOne on support.hibernate.entity.Task.employee references an unknown entity: support.hibernate.entity.Employee at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:97) ... at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1246) ...
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7
- Hibernate 5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.