We are using hibernate 3.2.5GA with level 2 cache turned on for most objects. Our ids are unique across all tables so most of our code just does Dao.get(id).
At the moment we have slow kludge to load the appropriate object by id using the HQL: "select obj from BaseClass obj where id=:id"
We don't mind the cost of this when the object is not in any cache but it seems a shame not to look in the caches first.
Assuming Session.load and Session.get don't do negative caching is there a supported way of peeking into the caches to see if our object is already there?
I can see how I can cast to SessionFactoryImpl, get all the caches, cobble together CacheKeys for each concrete entity class ... but I doubt my tech lead will be impressed.
btw We assume Session.get/load(BaseClass.class, id) is meant to fail with error about BaseClass not being mapped (we use @MappedSuperclass annotation).
Many thanks, sorry such a long posting.
Sam
|