What is Quarkus
Quarkus was developed to enable Java developers to create applications for a modern, cloud-native world. It is a Kubernetes-native Java framework tailored for GraalVM and HotSpot, crafted from best-of-breed Java libraries and standards. The basic goal is to make Java the leading platform in Kubernetes and serverless environments while offering developers a framework to address a wider range of distributed application architectures.
Hibernate Configuration with Quarkus
Hibernate ORM is the standard JPA implementation and offers you the full breadth of an Object Relational Mapper.
So, for the configuration to hibernate with Quarkus you need to create an application and add the required dependencies. The easiest way to do that is to use the interactive project generator at https://code.quarkus.io/. It will help you to define the metadata of your project and pick the required dependencies. For using Hibernate, make sure to select “Hibernate ORM” and the JDBC driver dependencies of your preferred database.
Setting up for Configuration
<! – Hibernate ORM – > <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-hibernate-orm</artifactId> </dependency> <! – JDBC driver dependencies – > <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-jdbc-postgresql</artifactId> </dependency>
This configuration uses Postgres as the username and password when connecting to the database test on localhost:5432 and also tells Hibernate to drop and create the database based on entity mappings and import the data.sql script.
Define the Entity
Injecting Entity manager
It will be created based on the Quarkus Datasource configuration, as long as the Hibernate ORM extension is registered among your project dependencies.
The entity objects you load from the database or for which you call the persist method is in the lifecycle state managed and Hibernate will include them in its dirty checks and automatically flush all changes to the database.
In Quarkus most of Hibernate’s configuration is based on smart defaults and the dependencies available on the classpath. Anyone can adjust all defaults and add their own configuration parameters to the configuration file.