Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions api/src/main/java/jakarta/persistence/AssociationOverride.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,21 @@
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. This element:
* <ul>
* <li>must be specified if a foreign key mapping is used in the
* overriding of the relationship mapping, but
* <li>must not be specified if a {@linkplain #joinTable join table}
* is used in the overriding of the relationship mapping.
* </ul>
*
* <p> 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 {};

Expand All @@ -163,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:
* <ul>
* <li>must not be specified if a {@linkplain #joinColumns foreign
* key mapping} is used in the overriding of the relationship
* mapping, but
* <li>must be specified if a join table is used in the overriding
* of the relationship mapping.
* </ul>
*
* @since 2.0
*/
Expand Down
23 changes: 14 additions & 9 deletions api/src/main/java/jakarta/persistence/CollectionTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
* <p> 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 {};

Expand All @@ -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
Expand Down
21 changes: 12 additions & 9 deletions api/src/main/java/jakarta/persistence/JoinColumns.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@
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.
*
* <p>Each {@link JoinColumn} annotation must explicitly specify both
* {@link JoinColumn#name name} and {@link JoinColumn#referencedColumnName
* referencedColumnName}.
* <p>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}
Comment thread
gavinking marked this conversation as resolved.
Resolved
* must be explicitly specified by every {@code JoinColumn} annotation.
*
* <p>Since {@code @JoinColumn} is a repeatable annotation, it's not usually
* necessary to specify {@code @JoinColumns} explicitly:
* <p>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")
* @JoinColumn(name = "ADDR_ZIP", referencedColumnName = "ZIP")
* public Address getAddress() { return address; }
* }
*
* <p>However, {@code @JoinColumns} is useful for controlling generation of
* composite foreign key constraints:
* <p>However, {@code @JoinColumns} is useful for controlling
* generation of composite foreign key constraints:
* {@snippet :
* @ManyToOne
* @JoinColumns(
Expand Down
27 changes: 22 additions & 5 deletions api/src/main/java/jakarta/persistence/JoinTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
* <p> Uses the same defaults as for {@link JoinColumn}.
*
* <p> 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.
*
* <p> Uses the same defaults as for {@link JoinColumn}.
*
* <p> 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 {};

Expand All @@ -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
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion api/src/main/java/jakarta/persistence/MapKeyJoinColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
24 changes: 16 additions & 8 deletions api/src/main/java/jakarta/persistence/MapKeyJoinColumns.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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.
*
* <p>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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have that snippet with an example for join columns:

* @ManyToOne
* @JoinColumns(
* value = {@JoinColumn(name = "ADDR_ID", referencedColumnName = "ID"),
* @JoinColumn(name = "ADDR_ZIP", referencedColumnName = "ZIP")},
* foreignKey = @ForeignKey(name = "PERSON_ADDRESS_FK"))
* public Address getAddress() { return address; }
* }

would it be worth having one here as well ?

*
* <p> 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
*
Expand Down
19 changes: 14 additions & 5 deletions api/src/main/java/jakarta/persistence/PrimaryKeyJoinColumns.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +28,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.
*
* <p>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.
*
* <p>Since {@code @PrimaryKeyJoinColumn} is a repeatable annotation,
* it's not usually necessary to specify {@code @PrimaryKeyJoinColumns}
Expand Down Expand Up @@ -86,15 +95,15 @@
* {@link PrimaryKeyJoinColumn#foreignKey foreignKey} element
* of one of the {@link PrimaryKeyJoinColumn} annotations are
* specified, the behavior is undefined.
* <li>If no {@link PrimaryKeyJoinColumn} annotation is specified
* in either location, a default foreign key strategy is
* selected by the persistence provider.
* <li>If no {@link ForeignKey} annotation is specified in either
* location, a default foreign key strategy is selected by the
* persistence provider.
* </ul>
*
* @since 2.1
*
* @see PrimaryKeyJoinColumn#foreignKey
*/
ForeignKey foreignKey() default @ForeignKey(ConstraintMode.PROVIDER_DEFAULT);
ForeignKey foreignKey() default @ForeignKey(PROVIDER_DEFAULT);

}
15 changes: 12 additions & 3 deletions api/src/main/java/jakarta/persistence/SecondaryTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 { ... }
* }
*
Expand Down Expand Up @@ -88,6 +90,13 @@
* primary table.
* <p> Defaults to the column(s) of the same name(s) as
* the primary key column(s) in the primary table.
*
* <p> 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 {};

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).</li>
* is no update count, that is, either the next result is a result set
* or there is no next update count.</li>
* <li> 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.</li>
Expand Down
32 changes: 16 additions & 16 deletions api/src/main/java/jakarta/persistence/criteria/CriteriaQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ public interface CriteriaQuery<T> extends AbstractQuery<T>, CriteriaSelect<T> {
* <p>The semantics of this method are as follows:
* <ul>
* <li>
* If the type of the criteria query is {@code CriteriaQuery<Tuple>}
* (i.e., a criteria query object created by either the {@code createTupleQuery}
* If the type of the criteria query is {@code CriteriaQuery<Tuple>}, 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.
*
* <li> If the type of the criteria query is {@code CriteriaQuery<X>}
* 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
* <li> If the type of the criteria query is {@code CriteriaQuery<X>} 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.
*
* <li> If the type of the criteria query is {@code CriteriaQuery<X[]>}
Expand Down Expand Up @@ -188,16 +188,16 @@ public interface CriteriaQuery<T> extends AbstractQuery<T>, CriteriaSelect<T> {
*
* <p> The semantics of this method are as follows:
* <ul>
* <li> If the type of the criteria query is {@code CriteriaQuery<Tuple>}
* (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.
* <li> If the type of the criteria query is {@code CriteriaQuery<Tuple>}, 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.
*
* <li> If the type of the criteria query is {@code CriteriaQuery<X>}
* 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
* <li> If the type of the criteria query is {@code CriteriaQuery<X>} 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.
*
Expand Down
Loading