Annotation Type UniqueKeys


  • @Target(TYPE)
    @Retention(RUNTIME)
    public @interface UniqueKeys
    UniqueKeys annotation describe one or more unique keys of an entity type. Different from JPA UniqueConstraint for entity tables, UniqueKeys can annotate an entity type or its superclass, and UniqueKeys annotation in a subclass will override that of its superclass. For example,
    
     @UniqueKeys({
         @UniqueKey(properties={"id"}),
         @UniqueKey(properties={"name", "phone"})
     })
     @Entity(name="Employee")
     public class Employee extends Person {
     
     }
     
     @UniqueKeys({
         @UniqueKey(properties={"id"}),
         @UniqueKey(properties={"name", "address"})
     })
     @MappedSuperclass
     abstract public class Person {
     
     }
     
    UniqueKeys will be validated when creating and changing entities before committed to persistence, and user friendly message will be displayed if any unique constraint is violated.

    Note that UniqueKeys annotation is for validation only and will not generate table unique constraints in DDL.

    Since:
    4.2
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      UniqueKey[] value
      a list of UniqueKey annotations
    • Element Detail

      • value

        UniqueKey[] value
        a list of UniqueKey annotations