Reputation: 331
Suppose we have an object graph as below:
Class A {
B b;
}
Class B {
C c;
}
Class C {
D d;
}
Class D {}
Now when I fetch the object A I want to fetch B and C using eager loading and D using lazy loading. How this can be done in JPA or Hibernate?
Upvotes: 0
Views: 73
Reputation: 59978
Just use eager in A for Object B and eager in B for Object C and lazy in C for object D
class A {
//eager
B b;
}
class B {
//eager
C c;
}
class C {
//lazy
D d;
}
class D {}
Upvotes: 1
Reputation: 120858
Assuming there is a connection between them, you can easily use FetchType.EAGER in B
and C
and FetchType.LAZY in D
.
This sort of can be achieved via @NamedEntityGraph
also.
Upvotes: 2