Quarkus with Hibernate

Reading Time: 2 minutes

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

Dependencies–>

<! – 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.

application.properties Configuration

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.

Conclusion

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.

References:

https://quarkus.io/guides/

Written by 

Deepak kumar is a Software Intern at Knoldus Inc. He has done Post Graduation from Ajay Kumar Garg Engineering College Ghaziabad. He has the knowledge of various programming languages. He is passionate about Java development and curious to learn Java Technologies. He is a quick learner, problem solver and always enjoy to help others. His hobbies playing Cricket and watching Hollywood movies.

Leave a Reply