Ebean does not need a default constructor and this means we can give our entity bean a constructor that takes arguments. Typically the arguments are properties that should always be supplied when creating a new bean of that type (and by implication are typically non-nullable).

public class Customer {

  long id;

  @NotNull @Length(100)
  String name;

  public Customer(String name) { = name;

  // getters and setters

class Customer(name : String) {

  var id: Long = 0

  var name: String = name


Now when we create a new Customer we know we must create it with a name.

For Kotlin we can now make name a non-nullable type. Ebean will treat Kotlin non-nullable types as NOT NULL from a database perspective as well giving us a tighter model.

Customer customer = new Customer("Hello entity bean")
val customer = Customer("Hello entity bean")

Kotlin has multiple constructor styles. See here for more information on the preferred constructor style for entity beans.