-
@Target({}) @Retention(RUNTIME) public @interface ForeignKeySpecifies 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.The
ConstraintModevalue 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:When the
ConstraintModevalue isCONSTRAINT, but theforeignKeyDefinition()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.- Since:
- 2.1
- See Also:
JoinColumn,JoinColumns,MapKeyJoinColumn,MapKeyJoinColumns,PrimaryKeyJoinColumn,JoinTable,CollectionTable,SecondaryTable,AssociationOverride
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description java.lang.StringforeignKeyDefinition(Optional) The foreign key constraint definition.java.lang.Stringname(Optional) The name of the foreign key constraint.java.lang.Stringoptions(Optional) A SQL fragment appended to the generated DDL which creates this foreign key.ConstraintModevalue(Optional) Used to specify whether a foreign key constraint should be generated when schema generation is in effect.
-
-
-
-
value
ConstraintMode value
(Optional) Used to specify whether a foreign key constraint should be generated when schema generation is in effect.ConstraintMode.CONSTRAINTspecifies that the persistence provider must generate a foreign key constraint. If theforeignKeyDefinition()element 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:
- jakarta.persistence.ConstraintMode.CONSTRAINT
-
-
-
options
java.lang.String options
(Optional) A SQL fragment appended to the generated DDL which creates this foreign key. May not be used in conjunction withforeignKeyDefinition().- Since:
- 3.2
- Default:
- ""
-
-