I am writing a query against a domain model where (for whatever reason) a one-to-many association is mapped with lazy=”false”. In my particular query, I’d rather fetch that collection lazily, because I don’t care about its contents. How can I reenable laziness for my particular query? Is this possible at all?
So far, I looked at Criteria.setFetchMode, but FetchMode.LAZY is merely a deprecated alias for FetchMode.SELECT …
Changing the mapping would probably be ideal, but I’d rather not risk affecting the existing queries.
Edit: We use Hibernate 3.3.2
I am not an expert myself, but browsing through the Hibernate book and consulting with a colleague didn’t give me any hint that this would be possible, rather the contrary.
Yours seems to be an unusual situation, not covered by Hibernate. The typical use case is the opposite: to use lazy fetching by default, and selectively enable eager fetching for queries where it is justified.