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…

Hibernate’s ResultTransformer in Hibernate 4, 5 & 6
| | |

Hibernate’s ResultTransformer in Hibernate 4, 5 & 6

Hibernate implements JPA’s standardized constructor expressions and @SqlResultSetMappings to map the results of your queries. And it also supports proprietary ResultTransformers. They provide a powerful and flexible way to map the result of your JPQL, Criteria, and native SQL query to a specific object structure. This can be entity or DTO objects, java.util.List or java.util.Map…

How to configure List semantics in Hibernate 6
|

How to configure List semantics in Hibernate 6

Based on its javadoc, a java.util.List is supposed to represent an ordered collection of values. But that’s not necessarily the case if you use it as the type of a to-many association or an ElementCollection. As I explained before, Hibernate can handle a java.util.List as a Bag or a List. Only the List mapping persists the order…