Skip to content

Commit 62848c3

Browse files
committed
javadoc for @PartitionKey
1 parent b931a06 commit 62848c3

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

hibernate-core/src/main/java/org/hibernate/annotations/PartitionKey.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,50 @@
1212
import static java.lang.annotation.RetentionPolicy.RUNTIME;
1313

1414
/**
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+
* &#064;Entity
31+
* &#064;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+
* &#064;Id &#064;GeneratedValue Long id;
41+
* &#064;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.
1655
*
1756
* @since 6.2
1857
*/
1958
@Target({METHOD, FIELD})
2059
@Retention(RUNTIME)
2160
public @interface PartitionKey {
22-
2361
}

0 commit comments

Comments
 (0)