There are probably times when you want to load the full object graph, and others when you want much less data (and don't want to pay the performance penalty associated with loading all this). So let's suppose your needs varies.
Hibernate lazy load in general, but you can load additional data using one of several methods (see Hibernate documentation for details):
- While your session is up (you didn't close it), if you query fields of A, they can be loaded on demand. This is extraordinarily easy and flexible, but can be inefficient if it makes a lot of database calls.
- You can create an HQL request to specify that you want to load A, but also some fields. Use FETCH in the query for this.
- You can do the same with the Criteria API. Instead of specifying a query, you make method calls.
Sample for lazy :
A a = ...; // load A
String name = a.getB().getName(); // triggers an implicit query to load B
Sample for HQL:
select a
from A a
left join a.b b
left join a.c c
where a.id = :id