The documentation says:
Quote:
It is possible to eagerly join the Phone and the Person entities to avoid the possible extra roundtrip for initializing the many-to-one association.
Example 475. JPA native query selecting entities with joined many-to-one association
Code:
List<Phone> phones = entityManager.createNativeQuery(
"SELECT * " +
"FROM Phone ph " +
"JOIN Person pr ON ph.person_id = pr.id", Phone.class )
.getResultList();
for(Phone phone : phones) {
Person person = phone.getPerson();
}
I have a very similar case but when I do the equivalent to this:
Code:
for(Phone phone : phones) {
Person person = phone.getPerson();
}
Hibernate sends new queries to every
Person I try to get from a
phone.