I'm writing an extension to Hibernate - a super-extra-lazy multimap. It will solve the following common problem:
Suppose you have a user and his emails. The naive solution:
public class User
{
public Set<Mail> mails;
...
}
will be excruciatingly slow on most operations. Besides, it will be 2nd-level-cache-unfriendly.
I'm going to add a new type "BigMultiMap" (I call them "bigmaps") which will allow to do something like this:
public class User
{
public BigMultiMap<Date, Mail> mails;
}
It will allow lazy loading by key ranges - i.e. it will lazily load ranges of keys and values from database by request.
I have studied the internals of Hibernate and so far it looks that my idea is possible.
I also want to support caching of _half-loaded_ bigmaps (there's no sense in storing COMPLETE bigmaps, but it makes a very good sense to store the accessed parts of it). However, Hibernate caches collections after they are _completely_ _initialized_ which never happens with the extra-lazy collections!
What is the reason for this behavior? IMO, it's much more logical to store collections during the flush.
Is it possible to add collection to the cache in the "PersistentCollection.postAction()" callback? I guess there might be issues with read-write caches and locking, but so far I only care about transactional caches.
PS: why am I disallowed posting in dev list?
_________________ Sapienti sat!
|