V
V
voshodnerd2020-07-21 17:13:40
Java
voshodnerd, 2020-07-21 17:13:40

How to implement partial JPA entity loading?

There is a JPA entity. It contains many classes that are also separate tables. The parent entity is associated with the child FetchType.EAGER. I would not want to touch the domain model, since it is used in a bunch of code and I don’t want to change it, and then something will fall off. That is, the parent entity itself is quite heavy. But the task arose of selecting only a few fields from the parent entity and some fields from the child communities (and not all of them). You can select an SQL query bypassing JPA, but then you need to implement pagination, but I would not want to lose it. If at all such a possibility?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2020-07-21
Hasanly @azerphoenix

I'm still learning Hibernate, but what if it's done using projections?
https://www.baeldung.com/spring-data-jpa-projections

However, more often than not, we don't need all the properties of the returned objects

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question