Thanks for the quick response! I'd like to outline my scenario and why I would like this feature, for posterity. Maybe a justification to include in 4.0.
I dutifully used surrogate keys as the primary identifiers for all my objects, as recommended in the wonderful book Hibernate in Action.
Our web site is internationalized, and one of the objects is a TranslationDomain, which has a property "code" that identifies it, that is also a natural key (unique=true). The web view layer makes calls to the service layer getTranslationDomainByCode("LoginPage") and getTranslationDomainByCode("PurchasePage"), etc, which it can then query by Locale to get the proper localized String to display.
These TranslationDomain objects are prime candidates for caching, since they rarely change. The problem is, the view layer only knows the codes (i.e. the natural keys), so it's missing the cache hit each time.
Of course, the view layer can maintain its own local cache of Translations, but... the Translations WILL change sometimes, (i.e., if we find a typo and want to correct it). So that's where the cache timeout provided by an ehcache would be awfully handy so we don't have to restart the web server to have the translation take effect! :-)
So, in closing, unless I'm missing an obvious solution here, it would just be really nice if hibernate could somehow use natural keys to identify cache hits.
Thanks for listening!
|