|
12 | 12 | import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
13 | 13 |
|
14 | 14 | /**
|
15 |
| - * Identifies a field of an entity that holds the partition key of a table. |
| 15 | + * Identifies a field of an entity that holds the |
| 16 | + * partition key of a table mapped by the entity |
| 17 | + * class. |
| 18 | + * <p> |
| 19 | + * If the partition key forms part of the unique |
| 20 | + * {@linkplain jakarta.persistence.Id identifier} |
| 21 | + * of the entity, this annotation is optional but |
| 22 | + * may still be applied for documentation purposes. |
| 23 | + * <p> |
| 24 | + * On the other hand, if the partition key is not |
| 25 | + * part of the identifier, use of this annotation |
| 26 | + * may improve the performance of SQL {@code update} |
| 27 | + * and {@code delete} statements. |
| 28 | + * <p> |
| 29 | + * <pre> |
| 30 | + * @Entity |
| 31 | + * @Table(name = "partitioned_table", |
| 32 | + * options = |
| 33 | + * """ |
| 34 | + * partition by range (pid) ( |
| 35 | + * partition p1 values less than (1000), |
| 36 | + * partition p2 values less than (2000) |
| 37 | + * ) |
| 38 | + * """) |
| 39 | + * class Partitioned { |
| 40 | + * @Id @GeneratedValue Long id; |
| 41 | + * @PartitionKey Long pid; |
| 42 | + * String text; |
| 43 | + * } |
| 44 | + * </pre> |
| 45 | + * Many databases are not able to maintain a unique |
| 46 | + * key constraint across multiple partitions unless |
| 47 | + * the unique key contains the partition key column. |
| 48 | + * On these databases, the column mapped by a field |
| 49 | + * annotated {@code @PartitionKey} is automatically |
| 50 | + * added to the generated primary key constraint. |
| 51 | + * In this case, the database is not able to enforce |
| 52 | + * uniqueness of the identifier value, and care must |
| 53 | + * be taken to ensure that the identifier is unique |
| 54 | + * across entity instances. |
16 | 55 | *
|
17 | 56 | * @since 6.2
|
18 | 57 | */
|
19 | 58 | @Target({METHOD, FIELD})
|
20 | 59 | @Retention(RUNTIME)
|
21 | 60 | public @interface PartitionKey {
|
22 |
| - |
23 | 61 | }
|
0 commit comments