I am doing some volunteer work for the local school district. We are using Hibernate for O/R mapping, and for general searches, we don't need much of the object graph returned. So I set fetch="join" in the XML for the parts of the object graph we want returned. However, we saw that Hibernate was doing n + 1 selects. Turns out it was for
this reason.
So I removed all fetch="join" entries from the XML and now use "left join fetch" in the HQL - problem solved.
But now if I want to drill down and get one entity and its object graph, I need to use"left join fetch" in the HQL and do a query rather than just loading it by its ID. The query returns a list of one object and I have to do a
to grab the first object to return the entity from the DAO (which seems ugly and I'd rather avoid).
Is there any way that I can just load the object using its ID and get the object graph? The only way I can see to get the object graph is to specify in the XML (which results in the n + 1 problem for queries) or to specify "left join fetch" in the HQL. I'd rather not do a full blown query since I already have the object's primary key id.
Thanks