Constraining Entity Fields

  • Required

    Defines whether the value of the field cannot be null.

    Example of use:

    entity Activity {
      name String required
    }
  • Unique

    Defines whether the field (or a list of fields) is a unique key.

    There are two ways of defining a unique constraint:

    • In-lined with the field definition (single unique field)

    • Defined with '@UniqueConstraint' annotation (single or multiple unique fields)

    Example of use:

    entity DayOfWeek {
      name String unique
    }
    
    @UniqueConstraint("id, lastName")
    entity Persons {
      id String
      lastName String
      firstName String
    }
  • Min/Max bounds

    Defines the min and/or the max values of a field.

    Example of use:

    entity {
      dayOfWeek Integer min(0) max(6)
    }
  • Length

    Defines the maximum length of a String field. Note that, by default, String fields do not have a maximum length and can contain large text data.

    Example of use:

    entity {
      zipCode String length(10)
    }
  • Field type and constraint association

    The following table lists the supported constraints by type.

    Example of use:

    Question Allowed Constraint
    String required, unique, length
    Instant required, unique
    LocalDate required, unique
    LocalTime required, unique
    LocalDateTime required, unique
    Duration required, unique
    Integer required, unique, min, max
    Long required, unique, min, max
    Double required, unique, min, max
    Boolean required, unique
    Binary required, unique