GemFire 6 - 8.1
The purpose of this article is to explain how to use region colocation with two regions with a 1:n relation.
If the regions have 1:1 relationship and they use the same key (and key type) a custom partition resolver is not needed. The only thing needed is to use the 'colocated-with' partition attribute:
<region name="Customer" refid="customer">
<partition-attributes colocated-with="Order" />
But in the case of using regions with a 1:n relationship it is not sufficient to define the colocated-with attribute because one key cannot point to many entries. For this scenario we are going to need a PartitionResolver when colocating regions. In the case of Customers and Orders, we can use either the customerId or a custom class containing the customerId as the key in the customers region and a custom class containing the customerId and orderId as the key in the orders region.
Then in the custom partition resolver we can get the customerId from Customer and Order and colocate on the customerId in the getPartitionName() method of the partition resolver.