Package org.hibernate.annotations
Annotation Interface PartitionKey
Identifies a field of an entity that holds the
partition key of a table mapped by the entity
class.
If the partition key forms part of the unique identifier of the entity, this annotation is optional but may still be applied for documentation purposes.
On the other hand, if the partition key is not
part of the identifier, use of this annotation
may improve the performance of SQL update
and delete
statements.
@Entity @Table(name = "partitioned_table", options = """ partition by range (pid) ( partition p1 values less than (1000), partition p2 values less than (2000) ) """) class Partitioned { @Id @GeneratedValue Long id; @PartitionKey Long pid; String text; }Many databases are not able to maintain a unique key constraint across multiple partitions unless the unique key contains the partition key column. On these databases, the column mapped by a field annotated
@PartitionKey
is automatically
added to the generated primary key constraint.
In this case, the database is not able to enforce
uniqueness of the identifier value, and care must
be taken to ensure that the identifier is unique
across entity instances.- Since:
- 6.2