The best way to fetch SQL query projections with JPA

The best way to fetch SQL query projections with JPA

Vlad Mihalcea

1 год назад

3,877 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Niladri Sekhar Nath
Niladri Sekhar Nath - 18.09.2023 23:21

Thanks for the most of the approaches demonstration but can you please tell me something for the result set we know what would be the value that we are selecting and we keep one DTO for the resultList for the values that would be coming to us, but what if we don't know what are the values that we are selecting(like we know that the fields are part of some Entity class) but we don't know what are the values that would be requested for us like sometimes five values are requested and sometimes 10 values so what should we do then ? Obviously we cannot create a ResultDTO for the values for every combination, then please suggest how to create a DTO for the resultSet for the values that would do something like when five fields are selected we set the five values and rest of the fields we set as null ? What would be the efficient way to do this ?

Ответить
Максим
Максим - 24.05.2023 22:01

Thank you for video! I have a question, can i create DTO projection if my entity have nested collections?

Ответить
maiers72
maiers72 - 03.11.2022 10:38

Thank you for all the information. Do you have some more information when to use which approach?

Ответить
BASSAM ALHARBI
BASSAM ALHARBI - 01.11.2022 20:43

👍🏻

Ответить
Swann
Swann - 01.11.2022 16:38

Please continue 🙏😍

Ответить
Kic Kicek
Kic Kicek - 01.11.2022 14:35

These approaches are much better than handling Object[] data but still look kind of complicated.
Why can't I just supply a random object with fields annotaded such that the framework code can figure out how to assign results to the fields.
Like (annotations made up, example simplified):

@MappableResult
public class PostDTO {

@ResultMapping(name = "id")
Long id;
@ResultMapping(name = "title")
String title;
}

Hibernate already does this with entities and @Column annotations, why not use a similar thing here?
Would this break some core principles of the framework?

Ответить
Muhammad Naeem
Muhammad Naeem - 01.11.2022 13:40

Very Informative

Ответить