views:

36

answers:

1

I've a collection mapped, which caches fine in the L2Cache. As soon as I apply a filter to the collection, the L2Cache is not used. I can't use a where clause in the collection as I need it to be more dynamic than that. Anyone have any ideas ??

A: 

One colleague of mine had a problem which sounds similar to this one. He found that if lazy loading is disabled, by default a join query is used to retrieve both the containing entity and the contained collection at once. However, join queries are not cached.

His solution was to switch to subselect query by setting fetch="select" in the mapping. Then both queries are cached independently.

Péter Török