tags:

views:

398

answers:

2

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

A: 

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.

Péter Török
I didn't find anything either. It appears one better does not deviate from hibernate's defaults. I have worked around the problem by projecting. (I didn't need the entire entities, though I'd rather have avoided defining a new DTO).
meriton
A: 

Woow, still no solution, I have a similar case where 99% of the time, the collection has to be fetched eagerly, but criteria does not work with fetchmode=lazy on a collection if it is mapped as eager besides it being deprecated and this does not make sense!