I have three entities:
@Entity
@Table(name="a")
class A {
@Id
Long id;
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "a_id")
Set<B> bs;
// ... other fields
}
@Entity
@Table(name = "b")
class B {
@Id
Long id;
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "c_id")
Set<C> cs;
// ... other fields
}
@Entity
@Table(name = "c")
class C {
@Id
Long id;
// ... other fields
}
When I use Criteria API from JPA to get given A, Hibernate first fetches just A, then for each A, all B's and finally for each B all C's.
Is it possible to force fetching with one select which is in theory possible?
Hibernate doesn't support well fetching multiple eager collections. Take a look here.
Btw do you really need those collection as eagerly loaded?