Mapping keys to partitions with PartitionKey annotations

[Version 8.6 and later]A PartitionKey alias is used to identify the fields or attributes on which a hash code calculation is run to determine the partition to which data is saved. The PartitionKey annotation is only valid on key attributes.

Before you begin

You must be using eXtreme Data Format (XDF). For more information, see Configuring data grids to use eXtreme data format (XDF).

About this task

You set a PartitionKey alias to ensure that multiple classes save data to the same partition. For example, if you set the PartitionKey value to be the departmentID key, employee records are collocated on the same partition.

The PartionableKey interface is the existing Java interface and has precedence over the PartitionableKey annotation in C#.

Procedure

  • [Java programming language only]Define PartitionKey annotations on a field in a Java application.
     class Employee {
         int empId;
    
         @PartitionKey(order = 0)
         int deptId;
         
    	}
    
    You can set PartitionKey annotations on multiple keys, or you can set the PartitionKey alias on a class. For more examples of how to set PartitionKey annotations in Java applications, see Java API documentation: Annotation Type PartitionKeys.
  • [.net programming language only]Define PartitionKey attributes on a field in a .NET application.
    class Employee {
        int empId;
    
        [PartitionKey]
        int deptId;
    }
    You can set also PartitionKey attributes on .NET classes. For more information, see .NET API documentation: PartitionKeyAttribute Class.