The best way to fetch a Spring Data JPA DTO Projection
Introduction In this article, I’m going to show you what is the best way to fetch a Spring Data JPA DTO Projection. Apart from the basic use cases, we’re going to see how to fetch even hierarchical DTO structures using Spring Data JPA.
How to fetch a one-to-many DTO projection with JPA and Hibernate
Introduction In this article, I’m going to show you how you can fetch a one-to-many relationship as a DTO projection when using JPA and Hibernate. While entities make it very easy to fetch additional relationships, when it comes to DTO projections, you need to use a ResultTransformer to achieve this goal.
The best way to use Java Records with JPA and Hibernate
Introduction In this article, I’m going to show you how you can use Java Records with JPA and Hibernate. Added since version 14 as a preview feature, Java Records allow us to create compact DTOs (Data Transfer Objects) or Value Objects.
How to write a compact DTO projection query with JPA
Introduction In this article, we are going to see how we can write the best DTO projection JPQL query by omitting the package name when using JPA, Hibernate, and Spring. As I already explained, DTO projections are the most efficient way of fetching data when using JPA and Hibernate.
How to use the Hibernate Query Cache for DTO projections
Introduction On the Hibernate forum, I noticed the following question which is about using the Hibernate Query Cache for storing DTO projections, not entities. While caching JPQL queries which select entities is rather typical, caching DTO projections is a lesser-known feature of the Hibernate second-level Query Cache.
The best way to map a projection query to a DTO (Data Transfer Object) with JPA and Hibernate
Introduction In this article, I’m going to show you the best way to map a DTO projection when using JPA and Hibernate. While answering questions on the Hibernate forum, I stumbled on the following question. What was different than previous questions on the same topic was that the original poster realized the shortcoming of the JPA constructor expression which can be addressed elegantly by Hibernate. Because this has been a recurring theme on StackOverflow and the Hibernate forum, I decided to dedicate an article to the best way of mapping DTO projections… Read More
Why you should use the Hibernate ResultTransformer to customize result set mappings
Introduction JPA queries allow you to fetch either entities or DTO projections. However, sometimes you want a combined result set as illustrated in this Hibernate forum question.