From f016e27959be7c1b9da0d6bc7d38a39bc9c8e256 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 24 Nov 2026 00:43:32 +0100 Subject: [PATCH 1/7] some clarifications to Javadoc of @XxxJoinColumns --- .../java/jakarta/persistence/JoinColumns.java | 21 +++++++++------- .../persistence/MapKeyJoinColumns.java | 24 ++++++++++++------- .../persistence/PrimaryKeyJoinColumns.java | 9 ++++++- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/jakarta/persistence/JoinColumns.java b/api/src/main/java/jakarta/persistence/JoinColumns.java index ebbcdaef2..4be009dc2 100644 --- a/api/src/main/java/jakarta/persistence/JoinColumns.java +++ b/api/src/main/java/jakarta/persistence/JoinColumns.java @@ -24,15 +24,18 @@ import static jakarta.persistence.ConstraintMode.PROVIDER_DEFAULT; /** - * Specifies the mapping for composite foreign keys. This annotation groups - * {@link JoinColumn} annotations for the same relationship. + * Specifies the mapping for a composite foreign key. This annotation + * groups {@link JoinColumn} annotations mapping the columns belonging + * to the foreign key. * - *

Each {@link JoinColumn} annotation must explicitly specify both - * {@link JoinColumn#name name} and {@link JoinColumn#referencedColumnName - * referencedColumnName}. + *

When a {@code JoinColumns} annotation contains more than one + * {@code JoinColumn} annotation, both the + * {@linkplain JoinColumn#name name} and the + * {@linkplain JoinColumn#referencedColumnName referenced column name} + * must be explicitly specified by every {@code JoinColumn} annotation. * - *

Since {@code @JoinColumn} is a repeatable annotation, it's not usually - * necessary to specify {@code @JoinColumns} explicitly: + *

Since {@code @JoinColumn} is a repeatable annotation, it's not + * usually necessary to specify {@code @JoinColumns} explicitly: * {@snippet : * @ManyToOne * @JoinColumn(name = "ADDR_ID", referencedColumnName = "ID") @@ -40,8 +43,8 @@ * public Address getAddress() { return address; } * } * - *

However, {@code @JoinColumns} is useful for controlling generation of - * composite foreign key constraints: + *

However, {@code @JoinColumns} is useful for controlling + * generation of composite foreign key constraints: * {@snippet : * @ManyToOne * @JoinColumns( diff --git a/api/src/main/java/jakarta/persistence/MapKeyJoinColumns.java b/api/src/main/java/jakarta/persistence/MapKeyJoinColumns.java index bd079d4a1..6b65b31b2 100644 --- a/api/src/main/java/jakarta/persistence/MapKeyJoinColumns.java +++ b/api/src/main/java/jakarta/persistence/MapKeyJoinColumns.java @@ -24,15 +24,23 @@ import static jakarta.persistence.ConstraintMode.PROVIDER_DEFAULT; /** - * Supports composite map keys that reference entities. + * Specifies the mapping of a map key of entity type to a + * composite foreign key. This annotation groups + * {@link MapKeyJoinColumn} annotations mapping the columns + * belonging to the foreign key. + * + *

When a {@code MapKeyJoinColumns} annotation contains + * more than one {@code MapKeyJoinColumn} annotation, both + * the {@linkplain MapKeyJoinColumn#name name} and the + * {@linkplain MapKeyJoinColumn#referencedColumnName + * referenced column name} must be explicitly specified by + * every {@code MapKeyJoinColumn} annotation. + * + *

Since {@code @MapKeyJoinColumn} is a repeatable annotation, + * it's not usually necessary to specify {@code @MapKeyJoinColumns} + * explicitly. However, {@code @MapKeyJoinColumns} is useful for + * controlling generation of composite foreign key constraints. * - *

The {@code MapKeyJoinColumns} annotation groups - * {@link MapKeyJoinColumn} annotations. When the - * {@code MapKeyJoinColumns} annotation is used, both the - * {@code name} and the {@code referencedColumnName} - * elements must be specified in each of the grouped - * {@code MapKeyJoinColumn} annotations. - * * @see MapKeyJoinColumn * @see ForeignKey * diff --git a/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java b/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java index 6432034c2..139404ea8 100644 --- a/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java +++ b/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java @@ -26,7 +26,14 @@ /** * Specifies the mapping for a composite foreign key which is also a * primary key. This annotation groups {@link PrimaryKeyJoinColumn} - * annotations. + * annotations mapping the columns belonging to the foreign key. + * + *

When a {@code PrimaryKeyJoinColumns} annotation contains more + * than one {@code PrimaryKeyJoinColumn} annotation, both the + * {@linkplain PrimaryKeyJoinColumn#name name} and the + * {@linkplain PrimaryKeyJoinColumn#referencedColumnName referenced + * column name} must be explicitly specified by every + * {@code PrimaryKeyJoinColumn} annotation. * *

Since {@code @PrimaryKeyJoinColumn} is a repeatable annotation, * it's not usually necessary to specify {@code @PrimaryKeyJoinColumns} From 47aaaa79d88155a6628ea60c60cd4050fc746585 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 24 Nov 2026 00:52:17 +0100 Subject: [PATCH 2/7] some clarifications to spec of @XxxJoinColumns --- .../ch11-metadata-for-or-mapping.adoc | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc index 99cef4af3..fbc4939d2 100644 --- a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc +++ b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc @@ -2683,13 +2683,11 @@ public Set getOrders() { return orders; } ==== JoinColumns Annotation -Composite foreign keys are supported by means -of the `JoinColumns` annotation. The `JoinColumns` annotation groups -`JoinColumn` annotations for the same relationship. +The `JoinColumns` annotation groups the `JoinColumn` annotations +that map the columns of a composite foreign key. -When the `JoinColumns` annotation is used, -both the `name` and the `referencedColumnName` elements must be -specified in each of the grouped `JoinColumn` annotations. +When `JoinColumns` contains more than one `JoinColumn` annotation, +each must explicitly specify both `name` and `referencedColumnName`. The `foreignKey` annotation element is used to specify or control the generation of a foreign key constraint when @@ -3953,13 +3951,12 @@ public class Student { ==== MapKeyJoinColumns Annotation -Composite map keys referencing entities are -supported by means of the `MapKeyJoinColumns` annotation. The -`MapKeyJoinColumns` annotation groups `MapKeyJoinColumn` annotations. +The `MapKeyJoinColumns` annotation maps a map key of entity type to +a composite foreign key. It groups the `MapKeyJoinColumn` annotations +that map the columns of the foreign key. -When the `MapKeyJoinColumns` annotation is -used, both the `name` and the `referencedColumnName` elements must be -specified in each of the grouped `MapKeyJoinColumn` annotations. +When `MapKeyJoinColumns` contains more than one `MapKeyJoinColumn` +annotation, each must explicitly specify both `name` and `referencedColumnName`. The `foreignKey` element specifies or controls the generation of a foreign key constraint for the columns @@ -4934,9 +4931,13 @@ public class ValuedCustomer extends Customer { ... } ==== PrimaryKeyJoinColumns Annotation -Composite foreign keys are supported by means -of the `PrimaryKeyJoinColumns` annotation. The `PrimaryKeyJoinColumns` -annotation groups `PrimaryKeyJoinColumn` annotations. +The `PrimaryKeyJoinColumns` annotation groups the `PrimaryKeyJoinColumn` +annotations that map the columns of a composite foreign key which is also +a primary key. + +When a class, field, or property has more than one `PrimaryKeyJoinColumn` +annotation, either repeated directly or grouped in `PrimaryKeyJoinColumns`, +each must explicitly specify both `name` and `referencedColumnName`. [source,java] ---- From 299d544abc234409eed44ba09bdc3848e854816b Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 25 Nov 2026 15:37:28 +0100 Subject: [PATCH 3/7] various join column javadoc fixes --- .../persistence/AssociationOverride.java | 19 +++++++---- .../jakarta/persistence/CollectionTable.java | 23 +++++++------ .../java/jakarta/persistence/JoinTable.java | 27 +++++++++++++--- .../jakarta/persistence/MapKeyJoinColumn.java | 4 ++- .../persistence/PrimaryKeyJoinColumns.java | 4 ++- .../jakarta/persistence/SecondaryTable.java | 15 +++++++-- .../persistence/StoredProcedureQuery.java | 4 +-- .../persistence/criteria/CriteriaQuery.java | 32 +++++++++---------- 8 files changed, 85 insertions(+), 43 deletions(-) diff --git a/api/src/main/java/jakarta/persistence/AssociationOverride.java b/api/src/main/java/jakarta/persistence/AssociationOverride.java index 21db5c33d..e7e738645 100644 --- a/api/src/main/java/jakarta/persistence/AssociationOverride.java +++ b/api/src/main/java/jakarta/persistence/AssociationOverride.java @@ -139,12 +139,19 @@ String name(); /** - * The join column(s) being mapped to the persistent attribute(s). - * The {@code joinColumns} elements must be specified if a foreign - * key mapping is used in the overriding of the mapping of the - * relationship. The {@code joinColumns} element must not be - * specified if a join table is used in the overriding of the - * mapping of the relationship. + * The join column or columns mapped by the persistent attribute + * or attributes. The {@code joinColumns} element must be + * specified if a foreign key mapping is used in the overriding + * of the mapping of the relationship. The {@code joinColumns} + * element must not be specified if a join table is used in the + * overriding of the mapping of the relationship. + * + *

When {@code joinColumns} specifies more than one + * {@code JoinColumn} annotation, both the + * {@linkplain JoinColumn#name name} and the + * {@linkplain JoinColumn#referencedColumnName referenced + * column name} must be explicitly specified by every + * {@code JoinColumn} annotation. */ JoinColumn[] joinColumns() default {}; diff --git a/api/src/main/java/jakarta/persistence/CollectionTable.java b/api/src/main/java/jakarta/persistence/CollectionTable.java index efe0611c3..b8790cce7 100644 --- a/api/src/main/java/jakarta/persistence/CollectionTable.java +++ b/api/src/main/java/jakarta/persistence/CollectionTable.java @@ -18,6 +18,8 @@ import java.lang.annotation.Target; import java.lang.annotation.Retention; + +import static jakarta.persistence.ConstraintMode.PROVIDER_DEFAULT; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.RetentionPolicy.RUNTIME; @@ -131,15 +133,18 @@ * (Optional) The foreign key columns of the collection table * which reference the primary table of the entity. The default * only applies if a single join column is used. The default is - * the same as for {@link JoinColumn} (i.e., the concatenation of - * the following: the name of the entity; "{@code _}"; the name of - * the referenced primary key column.) However, if there is more + * the same as for {@link JoinColumn}, that is, the concatenation + * of the following: the name of the entity; "{@code _}"; the name + * of the referenced primary key column. However, if there is more * than one join column, a {@link JoinColumn} annotation must be - * specified for each join column using the {@link JoinColumns} - * annotation. In this case, both the {@link JoinColumn#name name} - * and {@link JoinColumn#referencedColumnName referencedColumnName} - * elements must be specified by each such {@link JoinColumn} - * annotation. + * specified for each join column. + * + *

When {@code joinColumns} specifies more than one + * {@code JoinColumn} annotation, both the + * {@linkplain JoinColumn#name name} and the + * {@linkplain JoinColumn#referencedColumnName referenced + * column name} must be explicitly specified by every + * {@code JoinColumn} annotation. */ JoinColumn[] joinColumns() default {}; @@ -156,7 +161,7 @@ * * @since 2.1 */ - ForeignKey foreignKey() default @ForeignKey(ConstraintMode.PROVIDER_DEFAULT); + ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); /** * (Optional) Unique constraints that are to be placed on the diff --git a/api/src/main/java/jakarta/persistence/JoinTable.java b/api/src/main/java/jakarta/persistence/JoinTable.java index 84dfeb1d6..a8d89ce09 100644 --- a/api/src/main/java/jakarta/persistence/JoinTable.java +++ b/api/src/main/java/jakarta/persistence/JoinTable.java @@ -18,6 +18,8 @@ import java.lang.annotation.Target; import java.lang.annotation.Retention; + +import static jakarta.persistence.ConstraintMode.PROVIDER_DEFAULT; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; @@ -88,19 +90,34 @@ /** * (Optional) The foreign key columns of the join table * which reference the primary table of the entity owning - * the association. (I.e. the owning side of the association). + * the association, that is, the owning side of the + * association. * *

Uses the same defaults as for {@link JoinColumn}. + * + *

When {@code joinColumns} specifies more than one + * {@code JoinColumn} annotation, both the + * {@linkplain JoinColumn#name name} and the + * {@linkplain JoinColumn#referencedColumnName referenced + * column name} must be explicitly specified by every + * {@code JoinColumn} annotation. */ JoinColumn[] joinColumns() default {}; /** * (Optional) The foreign key columns of the join table * which reference the primary table of the entity that - * does not own the association. - * (I.e. the inverse side of the association). + * does not own the association, that is, the inverse + * side of the association. * *

Uses the same defaults as for {@link JoinColumn}. + * + *

When {@code inverseJoinColumns} specifies more + * than one {@code JoinColumn} annotation, both the + * {@linkplain JoinColumn#name name} and the + * {@linkplain JoinColumn#referencedColumnName referenced + * column name} must be explicitly specified by every + * {@code JoinColumn} annotation. */ JoinColumn[] inverseJoinColumns() default {}; @@ -117,7 +134,7 @@ * * @since 2.1 */ - ForeignKey foreignKey() default @ForeignKey(ConstraintMode.PROVIDER_DEFAULT); + ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); /** * (Optional) Used to specify or control the generation of a @@ -131,7 +148,7 @@ * * @since 2.1 */ - ForeignKey inverseForeignKey() default @ForeignKey(ConstraintMode.PROVIDER_DEFAULT); + ForeignKey inverseForeignKey() default @ForeignKey(PROVIDER_DEFAULT); /** * (Optional) Unique constraints to be placed on the table. diff --git a/api/src/main/java/jakarta/persistence/MapKeyJoinColumn.java b/api/src/main/java/jakarta/persistence/MapKeyJoinColumn.java index 154b853e7..f9775b31b 100644 --- a/api/src/main/java/jakarta/persistence/MapKeyJoinColumn.java +++ b/api/src/main/java/jakarta/persistence/MapKeyJoinColumn.java @@ -20,6 +20,8 @@ import java.lang.annotation.Repeatable; import java.lang.annotation.Target; import java.lang.annotation.Retention; + +import static jakarta.persistence.ConstraintMode.PROVIDER_DEFAULT; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; @@ -218,7 +220,7 @@ * * @since 2.1 */ - ForeignKey foreignKey() default @ForeignKey(ConstraintMode.PROVIDER_DEFAULT); + ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); /** * (Optional) Check constraints to be applied to the column. diff --git a/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java b/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java index 139404ea8..774d18945 100644 --- a/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java +++ b/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java @@ -18,6 +18,8 @@ import java.lang.annotation.Target; import java.lang.annotation.Retention; + +import static jakarta.persistence.ConstraintMode.PROVIDER_DEFAULT; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.TYPE; @@ -102,6 +104,6 @@ * * @see PrimaryKeyJoinColumn#foreignKey */ - ForeignKey foreignKey() default @ForeignKey(ConstraintMode.PROVIDER_DEFAULT); + ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); } diff --git a/api/src/main/java/jakarta/persistence/SecondaryTable.java b/api/src/main/java/jakarta/persistence/SecondaryTable.java index 14721754a..060e6dcf1 100644 --- a/api/src/main/java/jakarta/persistence/SecondaryTable.java +++ b/api/src/main/java/jakarta/persistence/SecondaryTable.java @@ -20,6 +20,8 @@ import java.lang.annotation.Repeatable; import java.lang.annotation.Target; import java.lang.annotation.Retention; + +import static jakarta.persistence.ConstraintMode.PROVIDER_DEFAULT; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; @@ -51,8 +53,8 @@ * @Table(name = "CUSTOMER") * @SecondaryTable(name = "CUST_DETAIL", * pkJoinColumns = { - * @PrimaryKeyJoinColumn(name = "CUST_ID"), - * @PrimaryKeyJoinColumn(name = "CUST_TYPE")}) + * @PrimaryKeyJoinColumn(name = "CUST_ID", referencedColumnName = "ID"), + * @PrimaryKeyJoinColumn(name = "CUST_TYPE", referencedColumnName = "TYPE")}) * public class Customer { ... } * } * @@ -88,6 +90,13 @@ * primary table. *

Defaults to the column(s) of the same name(s) as * the primary key column(s) in the primary table. + * + *

When {@code pkJoinColumns} specifies more than one + * {@code PrimaryKeyJoinColumn} annotation, both the + * {@linkplain PrimaryKeyJoinColumn#name name} and the + * {@linkplain PrimaryKeyJoinColumn#referencedColumnName + * referenced column name} must be explicitly specified + * by every {@code PrimaryKeyJoinColumn} annotation. */ PrimaryKeyJoinColumn[] pkJoinColumns() default {}; @@ -103,7 +112,7 @@ * * @since 2.1 */ - ForeignKey foreignKey() default @ForeignKey(ConstraintMode.PROVIDER_DEFAULT); + ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); /** * (Optional) Unique constraints that are to be placed on the diff --git a/api/src/main/java/jakarta/persistence/StoredProcedureQuery.java b/api/src/main/java/jakarta/persistence/StoredProcedureQuery.java index 4488683d8..8f23e7941 100644 --- a/api/src/main/java/jakarta/persistence/StoredProcedureQuery.java +++ b/api/src/main/java/jakarta/persistence/StoredProcedureQuery.java @@ -79,8 +79,8 @@ * {@link #getUpdateCount} method can be called to obtain the pending * result if it is an update count. The {@code getUpdateCount} method * will return either the update count (zero or greater) or -1 if there - * is no update count (i.e., either the next result is a result set or - * there is no next update count). + * is no update count, that is, either the next result is a result set + * or there is no next update count. *

  • For portability, results that correspond to JDBC result sets * and update counts need to be processed before the values of any * {@code INOUT} or {@code OUT} parameters are extracted.
  • diff --git a/api/src/main/java/jakarta/persistence/criteria/CriteriaQuery.java b/api/src/main/java/jakarta/persistence/criteria/CriteriaQuery.java index fd078001d..aeae0a2a2 100644 --- a/api/src/main/java/jakarta/persistence/criteria/CriteriaQuery.java +++ b/api/src/main/java/jakarta/persistence/criteria/CriteriaQuery.java @@ -130,17 +130,17 @@ public interface CriteriaQuery extends AbstractQuery, CriteriaSelect { *

    The semantics of this method are as follows: *

      *
    • - * If the type of the criteria query is {@code CriteriaQuery} - * (i.e., a criteria query object created by either the {@code createTupleQuery} + * If the type of the criteria query is {@code CriteriaQuery}, that is, + * a criteria query object created by either the {@code createTupleQuery} * method or by passing a {@link Tuple} class argument to the {@code createQuery} - * method), a {@link Tuple} object corresponding to the arguments of the + * method, a {@link Tuple} object corresponding to the arguments of the * {@code multiselect} method, in the specified order, will be instantiated and * returned for each row that results from the query execution. * - *
    • If the type of the criteria query is {@code CriteriaQuery} - * for some user-defined class X (i.e., a criteria query object created by - * passing a X class argument to the {@code createQuery} method), the arguments - * to the {@code multiselect} method will be passed to the X constructor and an + *
    • If the type of the criteria query is {@code CriteriaQuery} for some + * user-defined class X, that is, a criteria query object created by passing a + * X class argument to the {@code createQuery} method, the arguments to the + * {@code multiselect} method will be passed to the X constructor and an * instance of type X will be returned for each row. * *
    • If the type of the criteria query is {@code CriteriaQuery} @@ -188,16 +188,16 @@ public interface CriteriaQuery extends AbstractQuery, CriteriaSelect { * *

      The semantics of this method are as follows: *

        - *
      • If the type of the criteria query is {@code CriteriaQuery} - * (i.e., a criteria query object created by either the {@code createTupleQuery} - * method or by passing a {@link Tuple} class argument to the {@code createQuery} - * method), a {@code Tuple} object corresponding to the elements of the list passed - * to the {@code multiselect} method, in the specified order, will be instantiated - * and returned for each row that results from the query execution. + *
      • If the type of the criteria query is {@code CriteriaQuery}, that is, + * a criteria query object created by either the {@code createTupleQuery} method or + * by passing a {@link Tuple} class argument to the {@code createQuery} method, a + * {@code Tuple} object corresponding to the elements of the list passed to the + * {@code multiselect} method, in the specified order, will be instantiated and + * returned for each row that results from the query execution. * - *
      • If the type of the criteria query is {@code CriteriaQuery} - * for some user-defined class X (i.e., a criteria query object created by passing - * a X class argument to the {@code createQuery} method), the elements of the list + *
      • If the type of the criteria query is {@code CriteriaQuery} for some + * user-defined class X, that is, a criteria query object created by passing a X + * class argument to the {@code createQuery} method, the elements of the list * passed to the {@code multiselect} method will be passed to the X constructor * and an instance of type X will be returned for each row. * From 114073a96c9b3d02a3f0e82b511e3019e48e5cb6 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 25 Nov 2026 15:45:54 +0100 Subject: [PATCH 4/7] join column spec fixes --- .../ch11-metadata-for-or-mapping.adoc | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc index fbc4939d2..86c76ba87 100644 --- a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc +++ b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc @@ -176,12 +176,11 @@ is used. | |JoinColumn[] |joinColumns -|The -join column(s) being mapped to the persistent attribute(s). The -joinColumns element must be specified if a foreign key mapping is used -in the overriding of the mapping of the relationship. The joinColumns -element must not be specified if a join table is used in the overriding -of the mapping of the relationship +|The join columns of the relationship whose mapping is being overridden. +The `joinColumns` element must be specified if the override uses a foreign +key mapping and must not be specified if the override uses a join table. +When `joinColumns` contains more than one `JoinColumn` annotation, +each must explicitly specify both `name` and `referencedColumnName`. | |ForeignKey |foreignKey @@ -846,14 +845,11 @@ an underscore. |joinColumns |(Optional) The foreign key columns of the collection table which reference the primary table of the entity. -|(Default only applies if a single join -column is used.) The same defaults as for JoinColumn (i.e., the -concatenation of the following: the name of the entity; "`_`"; the name of -the referenced primary key column.) However, if there is more than one -join column, a JoinColumn annotation must be specified for each join -column using the JoinColumns annotation. Both the name and the -referencedColumnName elements must be specified in each such JoinColumn -annotation. +If there is more than one join column, `joinColumns` must contain a +`JoinColumn` annotation for each column, and each annotation must +explicitly specify both `name` and `referencedColumnName`. +|For a single join column, the entity name followed by an underscore +and the name of the referenced primary key column. |ForeignKey |foreignKey @@ -2827,15 +2823,18 @@ primary entity tables (owning side first), separated by an underscore. |joinColumns |(Optional) The foreign key columns of the join table which reference the primary table of the entity owning the -association (i.e. the owning side of the association). -|The same defaults as for JoinColumn. +association. When `joinColumns` contains more than one `JoinColumn` +annotation, each must explicitly specify both `name` and `referencedColumnName`. +|The same defaults as for `JoinColumn`. |JoinColumn[] |inverseJoinColumns |(Optional) The foreign key columns of the join table which reference the primary table of the entity that does not -own the association (i.e. the inverse side of the association). -|The same defaults as for JoinColumn. +own the association. When `inverseJoinColumns` contains more than one +`JoinColumn` annotation, each must explicitly specify both `name` and +`referencedColumnName`. +|The same defaults as for `JoinColumn`. |ForeignKey |foreignKey @@ -4833,7 +4832,9 @@ strategy will apply. <> lists the annotation elements that may be specified for the `PrimaryKeyJoinColumn` annotation and -their default values. +their default values. The defaults for `name` and `referencedColumnName` +apply only when a single `PrimaryKeyJoinColumn` annotation is specified +for the join. If no `PrimaryKeyJoinColumn` annotation is specified for a subclass in the `JOINED` mapping strategy, the foreign key @@ -5113,6 +5114,8 @@ public @interface SecondaryTable { |PrimaryKeyJoinColumn[] |pkJoinColumns |(Optional) The columns that are used to join with the primary table. +When `pkJoinColumns` contains more than one `PrimaryKeyJoinColumn` +annotation, each must explicitly specify both `name` and `referencedColumnName`. |Column(s) of the same name(s) as the primary key column(s) in the primary table |ForeignKey @@ -5181,8 +5184,8 @@ public class Customer { ... } @SecondaryTable( name="CUST_DETAIL", pkJoinColumns={ - @PrimaryKeyJoinColumn(name="CUST_ID"), - @PrimaryKeyJoinColumn(name="CUST_TYPE") + @PrimaryKeyJoinColumn(name="CUST_ID", referencedColumnName="ID"), + @PrimaryKeyJoinColumn(name="CUST_TYPE", referencedColumnName="TYPE") }) public class Customer { ... } ---- @@ -6907,4 +6910,4 @@ for this additional metadata contribution. Persistent providers may have a way to override this expectation and allow users to specify a different validation group or groups to be considered for DDL operations. -==== \ No newline at end of file +==== From bc34abfb5500c4da5d2f04970c2d5eee8754a041 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 25 Nov 2026 15:54:10 +0100 Subject: [PATCH 5/7] @AssociationOverride javadoc aesthetics --- .../persistence/AssociationOverride.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/jakarta/persistence/AssociationOverride.java b/api/src/main/java/jakarta/persistence/AssociationOverride.java index e7e738645..56551072d 100644 --- a/api/src/main/java/jakarta/persistence/AssociationOverride.java +++ b/api/src/main/java/jakarta/persistence/AssociationOverride.java @@ -140,11 +140,13 @@ /** * The join column or columns mapped by the persistent attribute - * or attributes. The {@code joinColumns} element must be - * specified if a foreign key mapping is used in the overriding - * of the mapping of the relationship. The {@code joinColumns} - * element must not be specified if a join table is used in the - * overriding of the mapping of the relationship. + * or attributes. This element: + *
          + *
        • must be specified if a foreign key mapping is used in the + * overriding of the relationship mapping, but + *
        • must not be specified if a {@linkplain #joinTable join table} + * is used in the overriding of the relationship mapping. + *
        * *

        When {@code joinColumns} specifies more than one * {@code JoinColumn} annotation, both the @@ -170,11 +172,14 @@ ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); /** - * The join table that maps the relationship. - * The {@code joinTable} element must be specified if a join table - * is used in the overriding of the mapping of the relationship. - * The {@code joinTable} element must not be specified if a foreign - * key mapping is used in the overriding of the relationship. + * The join table that maps the relationship. This element: + *

          + *
        • must not be specified if a {@linkplain #joinColumns foreign + * key mapping} is used in the overriding of the relationship + * mapping, but + *
        • must be specified if a join table is used in the overriding + * of the relationship mapping. + *
        * * @since 2.0 */ From 16b3241bda5385e3ad055028f3393d97282c207f Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 25 Nov 2026 16:02:26 +0100 Subject: [PATCH 6/7] fix a javadoc error --- .../java/jakarta/persistence/PrimaryKeyJoinColumns.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java b/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java index 774d18945..e249c6235 100644 --- a/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java +++ b/api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java @@ -95,9 +95,9 @@ * {@link PrimaryKeyJoinColumn#foreignKey foreignKey} element * of one of the {@link PrimaryKeyJoinColumn} annotations are * specified, the behavior is undefined. - *
      • If no {@link PrimaryKeyJoinColumn} annotation is specified - * in either location, a default foreign key strategy is - * selected by the persistence provider. + *
      • If no {@link ForeignKey} annotation is specified in either + * location, a default foreign key strategy is selected by the + * persistence provider. *
      * * @since 2.1 From 6dddf0e7e4f46e94323c177401fb2084ab1779b0 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 25 Nov 2026 16:20:40 +0100 Subject: [PATCH 7/7] robotic spec sync with Javadoc --- .../ch11-metadata-for-or-mapping.adoc | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc index 86c76ba87..e70ec5d3d 100644 --- a/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc +++ b/spec/src/main/asciidoc/ch11-metadata-for-or-mapping.adoc @@ -2516,10 +2516,12 @@ Support for referenced columns that are not primary key columns of the referenced table is optional. Applications that use such mappings are not portable. -The `foreignKey` annotation element is used -to specify or control the generation of a foreign key constraint when -schema generation is in effect. If this element is not specified, the -persistence provider's default foreign key strategy will apply. +The `foreignKey` element controls generation of the foreign key constraint +when schema generation is in effect. A `foreignKey` specified on an enclosing +`JoinColumns` annotation applies to the whole join. If both the enclosing +annotation and any grouped `JoinColumn` specify `foreignKey`, the behavior +is undefined. If no foreign key is specified for the join, the persistence +provider's default foreign key strategy applies. If more than one `JoinColumn` annotation is applied to a field or property, both the `name` and the @@ -2637,7 +2639,7 @@ join is for an element collection, the name of the collection table. |foreignKey |(Optional) The foreign key constraint for the join column. This is used only if table generation is in effect. -|Provider's default +|The constraint specified by the enclosing mapping, or the provider's default. |CheckConstraint[] |check @@ -2654,6 +2656,7 @@ only used if table generation is in effect. |String |options |(Optional) A SQL fragment appended to the generated DDL. +This element may not be used together with `columnDefinition`. |Nothing appended. |=== @@ -2698,7 +2701,7 @@ persistence provider's default foreign key strategy will apply. @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface JoinColumns { - JoinColumn[] value(); + JoinColumn[] value() default {}; ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); } ---- @@ -2713,8 +2716,10 @@ be specified for the `JoinColumns` annotation. |JoinColumn[] |value -|(Required) The join columns that map the relationship. -| +|(Optional) The join columns that map the relationship. If the array is +empty, the join columns are inferred as if `JoinColumns` were absent. +Thus `foreignKey` may be specified on its own. +|Empty array |ForeignKey |foreignKey @@ -3753,11 +3758,12 @@ referenced table. Support for referenced columns that are not primary key columns of the referenced table is optional. Applications that use such mappings are not portable. -The `foreignKey` element specifies -or controls the generation of a foreign key constraint for the map key -join column when table generation is in effect. If the `foreignKey` -element is not specified, the persistence provider's default foreign key -strategy is used. +The `foreignKey` element controls generation of the foreign key constraint +for the map key when table generation is in effect. A `foreignKey` specified +on an enclosing `MapKeyJoinColumns` annotation applies to the whole join. +If both the enclosing annotation and any grouped `MapKeyJoinColumn` specify +`foreignKey`, the behavior is undefined. If no foreign key is specified +for the join, the persistence provider's default foreign key strategy applies. If more than one `MapKeyJoinColumn` annotation is applied to a field or property, both the `name` and the @@ -3804,7 +3810,7 @@ field. |boolean |nullable |(Optional) Whether the foreign key column is nullable. -|true +|false |boolean |insertable @@ -3827,6 +3833,7 @@ when generating the DDL for the column. |String |options |(Optional) A SQL fragment appended to the generated DDL. +This element may not be used together with `columnDefinition`. |Nothing appended |String @@ -3852,7 +3859,7 @@ name of the primary table of the entity that is the value of the map. |(Optional) The foreign key constraint specification for the join column. This is used only if table generation is in effect. -|Provider's default +|The constraint specified by the enclosing mapping, or the provider's default. |CheckConstraint[] |check @@ -4824,11 +4831,13 @@ entityfootnote:[The derived id mechanisms described in <> are now to be preferred over `PrimaryKeyJoinColumn` for the `OneToOne` mapping case.]. -The `foreignKey` element specifies -or controls the generation of a foreign key constraint for the primary -key join column when table generation is in effect. If the `foreignKey` -element is not specified, the persistence provider's default foreign key -strategy will apply. +The `foreignKey` element controls generation of the foreign key constraint +on the primary key join column when table generation is in effect. +A `foreignKey` specified on an enclosing `PrimaryKeyJoinColumns` annotation +applies to the whole join. If both the enclosing annotation and any grouped +`PrimaryKeyJoinColumn` specify `foreignKey`, the behavior is undefined. +If no foreign key is specified for the join, the persistence provider's +default foreign key strategy applies. <> lists the annotation elements that may be specified for the `PrimaryKeyJoinColumn` annotation and @@ -4891,6 +4900,7 @@ a OneToOne primary key association. |String |options |(Optional) A SQL fragment appended to the generated DDL. +This element may not be used together with `columnDefinition`. |Nothing appended |ForeignKey @@ -4898,7 +4908,7 @@ a OneToOne primary key association. |(Optional) The foreign key constraint specification for the join column. This is used only if table generation is in effect. -|Provider's default +|The constraint specified by the enclosing mapping, or the provider's default. |CheckConstraint[] |check @@ -4945,7 +4955,7 @@ each must explicitly specify both `name` and `referencedColumnName`. @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface PrimaryKeyJoinColumns { - PrimaryKeyJoinColumn[] value(); + PrimaryKeyJoinColumn[] value() default {}; ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT); } ---- @@ -4969,8 +4979,10 @@ that may be specified for the `PrimaryKeyJoinColumns` annotation. |PrimaryKeyJoinColumn[] |value -|(Required) The primary key join columns. -| +|(Optional) The primary key join columns. If the array is empty, the +columns are inferred as if `PrimaryKeyJoinColumns` were absent. +Thus `foreignKey` may be specified on its own. +|Empty array |ForeignKey |foreignKey