Uploaded image for project: 'Hibernate ORM'
  1. HHH-12458

Use a SuperClass as target entity in a @OneToMany relationship

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects versions: None
    • Fix versions: None
    • Components: None
    • Labels:
      None
    • Last commented by a user?:
      true
    • Sprint:

      Description

      HI there,
      supposing to have an abstract SuperClass, with a single table inheritance, like this:

      @Entity
      @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
      @DiscriminatorFormula("...")
      @Table(name = "groups")
      public abstract class AbstractGroup<H extends AbstractGroup<H>> implements Serializable {
        @ManyToOne
        @JoinColumn(name = "parent_groupid", referencedColumnName = "groupid")
        private H parent;
      }
      

      You can receive this error message:

      Property entity.AbstractGroup.parent has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type.
      

      I think that you could accept target type as an instance of AbstractGroup, because you're using inheritance on a single table, so you could know which is the right class.

      What do you think about this?

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: