I have an entity class with multiple one-to-many entity classes.
All child classes having fetch type FetchType.EAGER
.
I have to fetch them with a limit and with parent class.
How can i do it in Hibernate JPA?
Asked
Active
Viewed 527 times
0

Zico
- 2,349
- 2
- 22
- 25
2 Answers
2
Make the OneToMany
relationship FetchType.LAZY
and then simply use JPA queries with Query.setMaxResults().

V G
- 18,822
- 6
- 51
- 89
-
I have wanted to fetch child objects with parent. If i use LAZY fetching then i have to retrieve child separately after parent. – Zico Jan 30 '15 at 11:46
-
1As I understand, you have a bidirectional relationship. The `OneToMany` part should be `FetchType.LAZY` and the `ManyToOne` `EAGER`, so that the parent is always fetched. – V G Jan 30 '15 at 11:51
0
My personal hint, it's just to avoid eager associations, but if this is a requirement. I could try max_fetch_depth property. Have a look on the hibernate documentation to know how it works.

Antonio Maria Sanchez Berrocal
- 1,713
- 15
- 15