Hibernate Data Repositories

A different way to use Hibernate.

A simpler and much more type-safe programming model for the persistence layer, and an implementation of Jakarta Data. Find your mistakes at compilation time.

Jakarta Data and Hibernate ORM

Hibernate Data Repositories is an implementation of the Jakarta Data specification targeting relational databases and backed by Hibernate ORM. Standard Jakarta Data repositories delegate persistence operations to a Hibernate StatelessSession.

Repository

In the example above, the Jakarta Data annotations @Repository, @Find, @Query, and @Insert are used together with JTA’s @Transactional and the Validation annotation @NotBlank.

Go here to see the five kinds of methods you’ll encounter on a repository interface.

Minimal magic

When you compile a repository interface, Hibernate Processor generates an implementation of the interface, meticulously checking for mistakes and inconsistencies, and reporting them using easily understandable compiler error messages.

The generated code is simple and extremely readable, and uses only public APIs of Hibernate ORM. It’s no more difficult to debug a repository than it is to debug your own hand-written Hibernate code.

Compatible with existing entities and queries

Entity classes are mapped using the familiar annotations defined by Jakarta Persistence, and queries may be written in the Hibernate Query Language, a superset of the Jakarta Data Query Language (JDQL). If you have existing entities and queries that already work in Hibernate ORM, you can use them without change in Hibernate Data Repositories.

On the other hand, the programming model for interacting with the database is quite different in Jakarta Data from the model you might be used to from Jakarta Persistence.

Compile-time type safety

Repository interfaces enable complete compile-time type safety for queries and other persistence operations. Hibernate Data Repositories includes a complete syntax validator and type checker for HQL, JPQL, and JDQL. Find mistakes in your queries immediately, without needing to run any tests.

Flexible sorting and paging

Jakarta Data features flexible APIs for limiting, sorting, and paging query results. Alongside standard offset / limit-style pagination, key-based pagination is also provided.

The static metamodel provides type safety for dynamic sorting criteria.

Sort

Reactive repositories

Complete integration with Hibernate Reactive is coming in Hibernate Data Repositories 7. A reactive repository method returns a reactive stream.

Reactive repository

Quarkus integration

Hibernate Data Repositories 6.6 works in Quarkus. Just add:

  • jakarta.data:jakarta.data-api and

  • org.hibernate.orm:hibernate-jpamodelgen

as dependencies via Maven.

Back to top