Unique Index

Unique constraints can be defined for an attribute or attributes of a space class. This will ensure that only one instance of the space class exists in the space with the specific attribute value. These indexes are applicable to all types of index; Equal, Ordered, Equal-and-Ordered, Compound, and Collection indexes.

The uniqueness is enforced per partition and not over the whole cluster.


When the system encounters a unique constraint violation in one of the index-changing api calls (write/update/change) a UniqueConstraintViolationException is thrown.

The operation which caused the violation is rolled back with the following effects:

Operation Action
write the entry is removed
update the original value is restored
change the original value is restored

If the operation(write or update) is performed under a transaction, the unique value check is done when the operation is performed (eager mode) and not when the transaction is committed.


A unique attribute is added to the @SpaceIndex annotation. Unique = true will designate a unique constraint.


public class Person
  @SpaceIndex(type=SpaceIndexType.EQUAL, unique = true)
  private String lastName;

  private String firstName;

  private Integer age;

    <class name="com.gigaspaces.examples.Person" persist="false" replicate="false" fifo="false" >
        <property name="lastName">
            <index type="EQUAL" unique="true"/>
        <property name="firstName">
            <index type="EQUAL"/>
        <property name="age">
             <index type="ORDERED"/>