12.2.2 Configuring Hibernate

Setting up a Hibernate/JPA EntityManager

Using the CLI

If you are creating your project using the Micronaut CLI, supply the hibernate-jpa feature to include a Hibernate JPA configuration in your project:

  1. $ mn create-app my-app features hibernate-jpa

Micronaut features built in support for configuring a Hibernate / JPA EntityManager that builds on the SQL DataSource support.

Once you have configured one or many DataSources to use Hibernate, you will need to add the hibernate-jpa dependency to your build configuration:

  1. implementation("io.micronaut.sql:micronaut-hibernate-jpa")
  1. <dependency>
  2. <groupId>io.micronaut.sql</groupId>
  3. <artifactId>micronaut-hibernate-jpa</artifactId>
  4. </dependency>

For more information see the Configuring Hibernate section of the Micronaut SQL libraries project.

Using GORM for Hibernate

For Groovy users and users familiar with the Grails framework, special support for GORM for Hibernate is available. To use GORM for Hibernate you should not include Micronaut’s built in SQL Support or the hibernate-jpa dependency since GORM itself takes responsibility for creating the DataSource, SessionFactory etc.

Using the CLI

If you are creating your project using the Micronaut CLI, supply the hibernate-gorm feature to include GORM, a basic connection pool configuration, and a default H2 database driver in your project:

  1. $ mn create-app my-app features hibernate-gorm

See the GORM Modules section of the Micronaut for Groovy user guide.