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
MappedSuperclass
has aOneToMany
association with a list/set of related entities (e.g.Task
). -
If
mappedBy
is used in theOneToMany
declaration and theManyToOne
references theMappedSuperclass
an exception is raised during deployment (whereEmployee
is theMappedSuperclass
referenced by aManyToOne
inTask
):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.