Jakarta Persistence (JPA) Annotation Type
jakarta.persistence.ForeignKey
- Implemented Interfaces:
Annotation
Specifies the handling of foreign key constraints when schema generation is in effect. If this annotation is not specified, a default foreign key strategy is selected by the persistence provider. [
( {, } ... ) ]
[ ON UPDATE ]
[ ON DELETE ]
The ConstraintMode value is used to specify whether foreign key constraints should be generated.
The syntax used in the foreignKeyDefinition element should follow the SQL syntax used by the target database for foreign key constraint creation. For example, it might be similar to the following:
FOREIGN KEY ( {, } ... ) REFERENCES
When the ConstraintMode value is CONSTRAINT, but the foreignKeyDefinition element is not specified, the provider will generate foreign key constraints whose update and delete actions it determines most appropriate for the join column(s) to which the foreign key annotation is applied.
- See Also:
- Since:
- Jakarta Persistence (JPA) 2.1
Annotation Elements
String nameDefaults to a provider-generated name.
- Default:
- ""
- Since:
- Jakarta Persistence (JPA) 1.0
ConstraintMode.CONSTRAINTspecifies that the persistence provider must generate a foreign key constraint. If theforeignKeyDefinitionelement is not specified, the provider will generate a constraint whose update and delete actions it determines most appropriate for the join column or columns to which the foreign key annotation is applied.ConstraintMode.NO_CONSTRAINTspecifies that no constraint should be generated.ConstraintMode.PROVIDER_DEFAULTselects the default behavior of the provider, which may or may not result in generation of a constraint.
- Default:
- CONSTRAINT
- Since:
- Jakarta Persistence (JPA) 1.0
String foreignKeyDefinition- Default:
- ""
- Since:
- Jakarta Persistence (JPA) 1.0
String optionsMay not be used in conjunction with
foreignKeyDefinition.- Default:
- ""
- Since:
- Jakarta Persistence (JPA) 3.2
Additional JDK methods inherited from java.lang.annotation.Annotation
annotationType(), equals(Object), hashCode(), toString()