Related: Trouble Shooting


We don't need a default constructor and this means we can give our entity beans a constructor that takes arguments. Typically the arguments are properties that should always be supplied when creating a new bean of that type.

e.g. Customer must have a name

The name property is now in the constructor and also we can make it a non null type. Ebean knows it is a non null type and DDL defines the column as NOT NULL.

class Customer(name : String) {

  var id: Long = 0

  var name: String = name


The test code now changes to:

val customer = Customer("Hello entity bean")

Kotlin non-null types

Ebean is aware of Kotlin non-null types and automatically maps those properties to database NOT NULL constraints.

e.g. Order must have a Customer and order date

The Order entity bean constructor takes both orderDate and customer and both are defined as NOT NULL from a code and DB perspective.


class Order(orderDate: LocalDate, customer: Customer) {

  var orderDate: LocalDate = orderDate

  var customer: Customer = customer

  // other properties


Edit Page