Annotation 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 ElementsModifier and TypeOptional ElementDescription(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
PrimaryKeyJoinColumn[] 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@PrimaryKeyJoinColumnsannotation was missing. This allows theforeignKey()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
foreignKeyelement of one of thePrimaryKeyJoinColumnannotations are specified, the behavior is undefined. - If no
PrimaryKeyJoinColumnannotation 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)
- If both this element and a
-