Annotation Interface PrimaryKeyJoinColumns


@Target({TYPE,METHOD,FIELD}) @Retention(RUNTIME) public @interface PrimaryKeyJoinColumns
Specifies the mapping for a composite foreign key which is also a primary key. This annotation groups PrimaryKeyJoinColumn annotations.

Since @PrimaryKeyJoinColumn is a repeatable annotation, it's not usually necessary to specify @PrimaryKeyJoinColumns explicitly:

@Entity
@Table(name = "VCUST")
@DiscriminatorValue("VCUST")
@PrimaryKeyJoinColumn(name = "CUST_ID",
                      referencedColumnName = "ID")
@PrimaryKeyJoinColumn(name = "CUST_TYPE",
                      referencedColumnName = "TYPE")
public class ValuedCustomer extends Customer { ... }

However, @PrimaryKeyJoinColumns is useful for controlling generation of composite foreign key constraints:

@Entity
@Table(name = "VCUST")
@DiscriminatorValue("VCUST")
@PrimaryKeyJoinColumns(
        value = {@PrimaryKeyJoinColumn(name = "CUST_ID",
                                       referencedColumnName = "ID"),
                 @PrimaryKeyJoinColumn(name = "CUST_TYPE",
                                       referencedColumnName = "TYPE")},
        foreignKey = @ForeignKey(name = "VCUST_CUST_FK"))
public class ValuedCustomer extends Customer { ... }
Since:
1.0
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    (Optional) Controls generation of the foreign key constraint on these primary key join columns when table generation is in effect.
    (Optional) The primary key columns that map the relationship.
  • Element Details

    • value

      (Optional) The primary key columns that map the relationship.

      If no @PrimaryKeyJoinColumns are specified, the columns are inferred according to the relationship mapping defaults, exactly as if the @PrimaryKeyJoinColumns annotation was missing. This allows the foreignKey() to be specified even when the primary key join columns are defaulted.

      Default:
      {}
    • foreignKey

      ForeignKey foreignKey
      (Optional) Controls generation of the foreign key constraint on these primary key join columns when table generation is in effect.
      • If both this element and a foreignKey element of one of the PrimaryKeyJoinColumn annotations are specified, the behavior is undefined.
      • If no PrimaryKeyJoinColumn annotation is specified in either location, a default foreign key strategy is selected by the persistence provider.
      Since:
      2.1
      See Also:
      Default:
      @jakarta.persistence.ForeignKey(PROVIDER_DEFAULT)