Annotation Interface PropertyRef


Allows to specify the target of a foreign-key using a "target attribute" as opposed to join column(s). E.g.
    @Entity
    class Employee {
        @Id
        Integer id;
        @Column(name="ssn")
        String socialSecurityNumber;
    }
    @Entity
    class TaxDetails {
        @Id Integer id;
        @OneToOne
        @PropertyRef("socialSecurityNumber")
        Employee employee;
    }
Generally more useful with composite keys:
    @Embeddable
    class Name {
        String first;
        String last;
    }
    @Entity
    class Employee {
        @Id
        Integer id;
        @Embedded
        Name name;
    }
    @Entity
    class TaxDetails {
        @Id Integer id;
        @OneToOne
        @PropertyRef("name")
        Employee employee;
    }
API Note:
As Hibernate allows OneToMany.mappedBy() and ManyToMany.mappedBy() to refer to basic and embedded attributes already, this annotation is mainly useful for mapping to-one associations.
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The name of the attribute on the target entity which defines the foreign-key target.
  • Element Details

    • value

      String value
      The name of the attribute on the target entity which defines the foreign-key target.