1. jpa-spec
  2. JPA_SPEC-39

Clarify requirements on polymorphic associations


    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:


      The 2.0 specification states in 2.9 that "Relationships are polymorphic", but there exists one case that appears to be completely valid JPA that Hibernate explicitly does not support. The specification should explicitly state whether a provider is required to support this case.

      When using a joined or single-table inheritance strategy, it is a common occurrence that an entity (e.g., Order) has a ManyToOne relationship with another entity (e.g., Customer). Since JPA supports class inheritance, it is possible that some of the Order instances are actually instances of a subclass (SpecialOrder), and we might want to have a Collection of just the SpecialOrder s on the Customer entity. (This is especially likely if Order is abstract and we want relationships directly to the subclasses.) An example class hierarchy looks like this:

      public class Customer {
        @OneToMany(mappedBy = "customer")
        private Set<SpecialOrder> specialOrders;
        @OneToMany(mappedBy = "customer")
        private Set<RegularOrder> regularOrders;
      public abstract class AbstractOrder {
        private Customer customer;
      public class SpecialOrder extends AbstractOrder {
        private Date shippingDate;
      public class RegularOrder extends AbstractOrder {
        private Integer storeNumber;

      The specification appears to imply but does not explicitly state that this arrangement is valid, while Hibernate explicitly requires that the mappedBy property be physically present on the exact class specified in the relationship mapping, not inherited from a superclass. This mismatch has inspired a surprising number of "how-to-work-around" blog posts and should be explicitly resolved for the next version of the specification.


        w_c_smith created issue -
        ldemichiel made changes -
        Field Original Value New Value
        Assignee ldemichiel [ ldemichiel ]


          • Assignee:
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: