Hibernate’s StatelessSession – What it is and how to use it

Hibernate’s StatelessSession – What it is and how to use it

Some of Hibernate’s core features are automatic dirty checks, flushes, and the 1st level cache. They make the implementation of most standard use cases simple and efficient. But they also add a lot of hidden complexity and are not a great fit for all use cases. Your typical nightly import job or most other use…

How to implement an AttributeConverter to support custom types
| |

How to implement an AttributeConverter to support custom types

All JPA implementations, including Hibernate, provide default mappings for a huge set of standard Java classes. You could model the attributes of all your entity classes using those mappings, and you would be able to map all columns of your table model. But this is often not the best fit for your business logic. A…

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…