Hibernate-specific extensions to the Criteria API
|

Hibernate-specific extensions to the Criteria API

Most developers know that the JPA specification defines the string-based JPQL query language and that Hibernate extends it to support things like database-specific functions, window functions, and set-based operations. But most developers don’t know that since version 6, Hibernate has done the same for JPA’s Criteria API. Extending an API is, of course, a little more complex…

Sequence naming strategies in Hibernate 6
|

Sequence naming strategies in Hibernate 6

Hibernate 6 introduced a new configuration parameter and an interface to define the implicit naming strategy for database sequences and tables used to generate primary key values. When you migrate an existing application to Hibernate 6, you quickly recognize that change because the default naming strategy has changed. Due to that, Hibernate might try using…

How to fix Hibernate’s Warning “HHH000104: firstResult/maxResults specified with collection fetch”

How to fix Hibernate’s Warning “HHH000104: firstResult/maxResults specified with collection fetch”

One of the most common recommendations to improve the performance of your persistence layer is to use JOIN FETCH clauses or EntityGraphs to fetch required associations when loading an entity. I entirely agree with these recommendations, and we discuss this in great detail in the Hibernate Performance Tuning course in the Persistence Hub. But if…

Hibernate’s @NotFound Annotation – How to use it and a better alternative

Hibernate’s @NotFound Annotation – How to use it and a better alternative

Some table models don’t enforce their foreign key references by a foreign key constraint. This is a bad practice that often leads to foreign key references that point to non-existing records. When Hibernate tries to resolve such a broken reference, it throws an EntityNotFoundException. You should, therefore, define a foreign key constraint for every foreign…