1. Ebean

Persistence module using Ebean: https://ebean.io

1.1. Usage

1) Add the dependencies (hikari + ebean):

Maven
Gradle
<!-- DataSource via HikariCP-->
<dependency>
  <groupId>io.jooby</groupId>
  <artifactId>jooby-hikari</artifactId>
  <version>2.6.1</version>
</dependency>

<!-- Ebean Module-->
<dependency>
  <groupId>io.jooby</groupId>
  <artifactId>jooby-ebean</artifactId>
  <version>2.6.1</version>
</dependency>

2) Add database driver (mySQL here):

Maven
Gradle
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.19</version>
</dependency>

3) Set database properties

application.conf
db.url = "jdbc:mysql://localhost/mydb"
db.user = myuser
db.password = mypass

4) Configure build time enhancement of the entity beans

Maven
Gradle
<plugin>
  <groupId>io.repaint.maven</groupId>
  <artifactId>tiles-maven-plugin</artifactId>
  <version>${tiles-maven-plugin.version}</version>
  <extensions>true</extensions>
  <configuration>
    <tiles>
      <!-- other tiles ... -->
      <tile>io.ebean.tile:enhancement:12.1.9</tile>
    </tiles>
  </configuration>
</plugin>

4) Install and use Ebean

Java
Kotlin
import io.jooby.hikari.HikariModule;
import io.jooby.ebean.EbeanModule;

{
  install(new HikariModule());                     (1)

  install(new EbeanModule());                      (2)

  get("/", ctx -> {
    Database db = require(Database.class);         (3)
    // work with Database
  });
}
1 Install and creates a DataSource
2 Install and Ebean
3 Use Ebean Database

1.2. Transactional Request

The TransactionalRequest decorator takes care of a start/commit/rollback a transaction per HTTP request.

TransactionalRequest
Java
Kotlin
import io.jooby.hikari.HikariModule;
import io.jooby.ebean.EbeanModule;
import io.jooby.ebean.TransactionalRequest;

{
  install(new HikariModule());

  install(new HibernateModule());

  decorator(new TransactionalRequest());

  post("/create", ctx -> {
    Database db = require(Database.class);

    MyEntity e = ...;

    db.save(e);

    return e;
  });
}

1.3. Configuration

Advanced/Custom configuration is supported programmatically or using property files.

Programmatically
Java
Kotlin
{
  DatabaseConfig dbConfig = ...;         (1)
  install(new EbeanModule(dbConfig));    (2)
}
1 Manually creates a database config or use the one provided by Jooby: create(Jooby,String).
2 Install Ebean with custom database config
Configuration
{
  ebean {
    ddl {
      generate = true
      run = true
    }
  }
}

Example shows how to setup Ebean migration tools. Keep in mind Jooby offers a better solution for database migrations Flyway Module.