-
@Target(value={}) @Retention(value=RUNTIME) public @interface ForeignKey
Used to specify the handling of foreign key constraints when schema generation is in effect. If this annotation is not specified, the persistence provider's default foreign key strategy will be used.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 constraints. For example, this may be similar the following:FOREIGN KEY ( <COLUMN expression> {, <COLUMN expression>}... ) REFERENCES <TABLE identifier> [ (<COLUMN expression> {, <COLUMN expression>}... ) ] [ ON UPDATE <referential action> ] [ ON DELETE <referential action> ]
When theConstraintMode
value 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:
- Java Persistence 2.1
- See Also:
JoinColumn
,JoinColumns
,MapKeyJoinColumn
,MapKeyJoinColumns
,PrimaryKeyJoinColumn
,JoinTable
,CollectionTable
,SecondaryTable
,AssociationOverride
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element and Description String
foreignKeyDefinition
(Optional) The foreign key constraint definition.String
name
(Optional) The name of the foreign key constraint.ConstraintMode
value
(Optional) Used to specify whether a foreign key constraint should be generated when schema generation is in effect.
-
-
-
Element Detail
-
name
public abstract String name
(Optional) The name of the foreign key constraint. If this is not specified, it defaults to a provider-generated name.- Default:
- ""
-
-
-
value
public abstract ConstraintMode value
(Optional) Used to specify whether a foreign key constraint should be generated when schema generation is in effect.A value of
CONSTRAINT
will cause the persistence provider to 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(s) to which the foreign key annotation is applied.A value of
NO_CONSTRAINT
will result in no constraint being generated.A value of
PROVIDER_DEFAULT
will result in the provider's default behavior (which may or may not result in the generation of a constraint for the given join column(s).- Default:
- javax.persistence.ConstraintMode.CONSTRAINT
-
-
-
foreignKeyDefinition
public abstract String foreignKeyDefinition
(Optional) The foreign key constraint definition.- Default:
- ""
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/08/2025 20:17:39 Cette version de la page est en cache (à la date du 21/08/2025 20:17:39) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 11/06/2005, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/persistence/foreignkey.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.