With @Index we can specify additional indexes. We can use this to specify uniqueness, function based indexes, compound indexes, platform specific indexes and if the indexes should be created concurrently (Postgres only at this stage).


This defines if the index is unique. This supports simple unique indexes but also function based unique indexes (e.g. unique lower name), compound uniqueness (multiple columns) and platform specific syntax.

For simple cases we can alternatively use @Column(unique=true) or @UniqueConstraint.


The platforms attribute limits the database platforms that the index should apply to. It is used so that we can define platform specific index definitions.

We can alternatively specify platform specific DDL for indexes via extra-dll.xml.

@Index(platforms = Platform.H2, unique = true, columnNames = {"name"})
@Index(platforms = Platform.POSTGRES, unique = true, name = "uq_printer_name", columnNames = {"lower(name)"})
@Table(name = "printers")
public class DPrinter extends Model {

In the above example we specify multiple @Index with the Postgres specific one using a function based index lower(name).


For Postgres this indicates the index should be created concurrently. For all other platforms this attribute is ignored.


The definition attribute allows use to specify the full DDL to create the index. When we do this we should specify the index name in order to support dropping the index.

  platforms = Platform.POSTGRES,
  name = "ix_detail_lowername",
  definition = "create index ix_detail_lowername on t_detail using hash (lower(name)) where lower(name) like 'r%'")

Often this index DDL will be platform specific and if we are testing against multiple database plaforms we specify the platforms that the index DDL applies to.