I am about to file a bug but wanted to run this by the experts first.
Let's say there is a User entity class that declares 20 lazy collections much like
@OneToMany( mappedBy = "owner")
@BatchSize(size = 1000)
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public Set<CustomSpace> getCustomSpaces()
In Hibernate 3.3.1.GA if I load ~1000 User entities from second level cache (w/o accessing
any of the collections), I'll end up spending 5x time assembling cache entries vs.
actually loading de-hydrated state from the cache provider (profiler snapshot attached).
Most of the time is spent eagerly assembling CollectionTypes, all of which may or may not
be needed during a given Session.
So, basically, I'm being penalized for merely declaring OneToMany's. Currently,
the only way to avoid this penalty - as far as I can tell - is to complicate the domain
model by introducing some number of new entities that will be OneToOne to User; and
redistributing collection declarations amongst those. But even that may not help: what if
services using the domain model access a variety of collections at different times? IMO a
much more scalable approach would be to:
* stash serialized states representing collection properties during assembleCacheEntry
* call CollectionType.assemble lazily when collection property field is actually accessed
(a la lazy properties)
Fwiw, a post covering the above in a little more detail can be found here: