Array type

We can use @DbArray to map a Set or List of String, UUID, Integer or Long.

public class Customer {

  private long id;

  private String name;

  private Set<String> tags = new LinkedHashSet<>();

  // getters and setters
class Customer(name: String) {

  var id: Long = 0

  var name: String = name

  var tags = emptyMutableSet<>();


DDL for Array types

In the above example the tags property maps to a varchar[].

create table customer (
  id                            bigserial not null,
  name                          varchar(255) not null,
  registered                    date,
  tags                          varchar[],
  version                       bigint not null,
  when_created                  timestamptz not null,
  when_modified                 timestamptz not null,
  constraint pk_customer primary key (id)

Array contains expression

Commonly we want to use the contains expression.

final List<Customer> customers
  = new QCustomer()
val customers
  = QCustomer()

The SQL for the above query is:

select,, t0.registered, t0.tags, t0.version, t0.when_created, t0.when_modified
  from customer t0
 where t0.tags @> array[?]; --bind(BLUE)