We have a database job which imports new data daily outside of hibernate's control. Since this job runs at roughly the same time every day, we have a scheduled job within our app server (JBOSS) which re-caches some of the more popular, long-running queries.
I've RTFM and some of the source but I don't see anyway to tell Hibernate to ignore the cached data, go to the database and reload the cache for a particular query -- note that simply nuking the whole cache or region isn't really a good option.
If something were to exist, I would guess a logical implementation would be as an optional flag for setCacheable: query.setCacheable(true
, Cache.FORCE_REFRESH) or maybe another method call:
Code:
List blogs = sess.createQuery("from Blog blog where blog.blogger = :blogger order by blog.datetime desc")
.setEntity("blogger", blogger)
.setCacheable(true)
.setCacheForceRefresh(true)
.setCacheRegion("frontpages")
.list();
So the specific questions:
- Did I miss something? Is there already an easy way to do this?
- What do you think of the idea? Might this be something interesting for future releases of Hibernate?
- Do you have any implementation ideas on this? (We might be able to do the code on this)
thanks.