Skip to content

Commit 002978d

Browse files
Update README.md
1 parent b140acd commit 002978d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4019,3 +4019,17 @@ From Openjdk JEP359:
40194019
Define the `AuthorDto` as:
40204020

40214021
`public record AuthorDto(String name, int age) implements Serializable {}`
4022+
4023+
-----------------------------------------------------------------------------------------------------------------------
4024+
4025+
274. **[How To Fetch DTO Via JDK14 Records And A Custom `ResultTransformer`](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootDtoRecordResultTransformer)**
4026+
4027+
**Description:** Fetching more *read-only* data than needed is prone to performance penalties. Using DTO allows us to extract only the needed data. Sometimes, we need to fetch a DTO made of a subset of properties (columns) from a parent-child association. For such cases, we can use SQL `JOIN` that can pick up the desired columns from the involved tables. But, `JOIN` returns an `List<Object[]>` and most probably you will need to represent it as a `List<ParentDto>`, where a `ParentDto` instance has a `List<ChildDto>`. For such cases, we can rely on a custom Hibernate `ResultTransformer`. This application is a sample of writing a custom `ResultTransformer`.
4028+
4029+
As DTO, we rely on JDK 14 Records. From Openjdk JEP359:
4030+
4031+
*Records provide a compact syntax for declaring classes which are transparent holders for shallowly immutable data.*
4032+
4033+
**Key points:**
4034+
- define the Java Records as `AuthorDto` and `BookDto`
4035+
- implement the `ResultTransformer` interface

0 commit comments

Comments
 (0)