Related: Trouble Shooting


We can use @MappedSuperclass for common properties used across many entity beans.

It is common to have a mapped superclass with @Id, @Version and @WhenModified properties like:

package org.example.domain

import io.ebean.annotation.WhenCreated
import io.ebean.annotation.WhenModified
import java.time.Instant
import javax.persistence.Id
import javax.persistence.MappedSuperclass
import javax.persistence.Version

open class BaseDomain {

  var id: Long = 0

  var version: Long = 0

  lateinit var whenModified: Instant

  lateinit var whenCreated: Instant


Our entity beans then extend this to inherit the common properties.

Note that we are using Kotlin lateinit on the @WhenModified and @WhenCreated properties. We are treating these as non-null types that will have their values set when the bean is saved.

Customer extends BaseDomain

package org.example.domain

import javax.persistence.Entity

class Customer(var name: String) : BaseDomain()

Order extends BaseDomain

package org.example.domain

import java.time.LocalDate
import javax.persistence.*

class Order(

  var orderDate: LocalDate,

  var customer: Customer

): BaseDomain()

Edit Page