Hibernate ORM 6.3.0.CR1 has just been released. Simultaneously, 6.2.7 has also been released.

New documentation

6.3 provides 2 new documentation guides:

  1. An introductory Hibernate 6 Guide

  2. The Hibernate Query Language synatx and feature guide

Query methods

Hibernate can now generate DAO-style methods for named queries as part of its JPA static metamodel generator.

Take the following entity as an example:

@NamedQuery(name = "#findByTitleAndType",
        query = "select book from Book book where book.title like :titlen and book.type = :type")
public class Book { ... }

When processed by the metamodel generator, we will now have the following generated into the static metamodel:

class Book_ {
    // as normal

    public static final String QUERY_FIND_BY_TITLE_AND_TYPE = "#findByTitleAndType";

    public static List<Book> findByTitleAndType(@Nonnull EntityManager entityManager, String title, Type type) {
        return entityManager.createNamedQuery(QUERY_FIND_BY_TITLE_AND_TYPE)
                .setParameter("titlePattern", title)
                .setParameter("type", type)

And the application can then use:

List<Book> books =
        Book_.findByTitleAndType(entityManager, titlePattern, Type.BOOK);

There are a lot of capabilities to these query methods; see the Hibernate 6 Guide for a full discussion.

Finder methods

Using the new @Find annotation, arbitrary methods can now be processed by the generator to create finder methods similar to query methods.

interface Dao {
    Book findBookByIsbn(String isbn);

The generator will generate:

class Dao_ {
        public static Book findBookByIsbn(@Nonnull EntityManager entityManager, String isbn) {
                return entityManager.unwrap(Session.class)
                                .using(Book_.isbn, isbn)

Again, there are a lot of capabilities to these finder methods; see the Hibernate 6 Guide for a full discussion.


For additional details, see:

See the website for getting in touch with us.

Back to top