Does anyone have a nice way to take advantage of fetching the parent + child data in one database visit while minimising clutter in the DAO layer?
session.createQuery("select p from Person p left join fetch p.addresses where p.id = ?", id).uniqueResult();
will retrieve a single Person and all of their Addresses in a single trip to the DB. So will the following:
What's the best approach out of:
1. Adding additional DAO methods as required which pre-fetch differing amounts of data using HQL, or
2. Parameterising DAO methods with the additional child data they should retrieve, and possibly using the session.createCriteria approach instead of HQL, or
We've currently got a business logic layer and a DAO layer, but seems like adding some additional service/use-case layer might be a good place to handle these considerations. The thing is, you probably still don't want HQL leaking up into any service layer.