Outer Joins and Explicit Fetching
Generally, one of the best way to improve performance is to limit the number of trips to the database. Hibernate has a number ways its handles the N+1 issue. Associations can be explicitly flagged for outer join fetching (via outer-join="true"), and you can add outer join fetching to HQL statements. For example...
/**
* @hibernate.many-to-one column="gold_claim_id"
* cascade="save-update" outer-join="true"
*/
public GoldClaim getGoldClaim() { return goldClaim; }
// This does one select and fetches both the Miner and GoldClaim
// and maps them correctly.
Miner m = (Miner) session.load(Miner.class, new Long(1));
In addition, when selecting lists or dealing with collection associations, you can use an explicit outer join fetch, like so...
// Issues a single select, instead of 1 + N (where N is the # miners)
List list = session.find("from Miner m left join fetch m.goldClaim");
--------------------------------------------------------
Please Refer Also
http://www.tim-wellhausen.de/papers/Que ... ngine.html