This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
What I am seeing is that when I issue an HQL query intended to retrieve a filtered list of a single object, it is immediatley followed by individual selects to retrieve an associated object for each item returned by the original query. I've been reading through Hibernate in Action regarding mapppings and HQL queries and have not been able to figure out how to suppress the additional selects being issued.
For class GiftCode, I have this bi-directional one-to-one association defined, (recently adding the outer-join attribute)
When I run this simple query: select giftCode from GiftCode giftCode where giftCode.redeemed = 'N' and giftCode.expirationDate < ?
I may get back 5 GiftCode objects, but then 5 selects are issued for GiftCredits. I realize I could add a fetch join, but I do not need those GiftCredits returned. Is there any way to suppress these additional selects?
Which version of Hibernate are you using? By default Hibernate has lazy loading on, did you change that anywhere? you can remove the outer-join="true" and you can put lazy="true" in the relation mapping, but like I said lazy="true" is the default.
In 3.2 Lazy is the default. So remove outerjoins="true" and lets see your entire mapping, because somewhere must be set to turn that off, or in your code you are getting the parent and either looping through the collection, or maybe just calling size() on the collection, which could cause Hibernate to load the collection.