Lombok support

Doma supports Lombok 1.16.12 or above.

Note

If you intend to use Eclipse, use version 4.5 or above.

Overview

Both Lombok and Doma provide annotation processors. Because the execution order of annotation processors is not determined in Java, Doma’s annotation processors are not always aware of the class modifications made by Lombok annotation processors.

To resolve the issue, Doma’s annotation processors recognize several of Lombok’s annotations and change their behavior. For example, if Doma’s annotation processors find a class annotated with @lombok.Value, they suppose that the class has a constructor whose arguments cover all instance fields.

Best practices

We show you recommended ways to define classes with Lombok annotations.

Entity class definition

immutable entity classes

  • Specify true to the immutable element of @Entity
  • Specify either @lombok.Value or @lombok.AllArgsConstructor
  • Specify @lombok.Getter to generate getters, in case of @lombok.AllArgsConstructor
@Entity(immutable = true)
@Value
public class Employee {
  @Id
  Integer id;
  String name;
  Age age;
}
@Entity(immutable = true)
@AllArgsConstructor
@Getter
public class Worker {
  @Id
  private final Integer id;
  private final String name;
  private final Age age;
}

mutable entity classes

  • Define a default constructor
  • Specify @lombok.Data or @lombok.Getter/@lombok.Setter to generate getters/setters
@Entity
@Data
public class Person {
  @Id
  private Integer id;
  private String name;
  private Age age;
}
@Entity
@Getter
@Setter
public class Businessman {
  @Id
  private Integer id;
  private String name;
  private Age age;
}

Domain class definition

  • Specify @lombok.Value
  • Define only one instance field whose name is value
@Domain(valueType = Integer.class)
@Value
public class Age {
  Integer value;
}

Embeddable class definition

  • Specify either @lombok.Value or @lombok.AllArgsConstructor
  • Specify @lombok.Getter to generate getters, in case of @lombok.AllArgsConstructor
@Embeddable
@Value
public class Address {
  String street;
  String city;
}
@Embeddable
@AllArgsConstructor
@Getter
public class Location {
  private final String street;
  private final String city;
}