Define a OneToMany association in a MappedSuperclass when using Hibernate

Solution Verified - Updated -

Issue

  • A MappedSuperclass (e.g. Employee) is defined as the parent of multiple subclasses.
  • The inheritance hierarchy rooted at the MappedSuperclass has a OneToMany association with a list/set of related entities (e.g. Task).
  • If mappedBy is used in the OneToMany declaration and the ManyToOne references the MappedSuperclass an exception is raised during deployment (where Employee is the MappedSuperclass referenced by a ManyToOne in Task):

    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.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content