Here is the scenario,
We have an entity, which is the result of a native query, joining 3 tables together. We have query cache as well as second level cache enabled. We are testing the timeToLiveInSeconds attribute. Every 15 minutes, we want the cache to refresh. But for testing purposes we've set this attribute to 5s and running multiple sequential queries over and over.
What we see is, 1) first hit - not in cache, hit the database and cache results 2) second hit - IS in cache - ok, return cached results 3) third hit - IS in cache, but expired (TTL expired), so ehcache returns null * This is where the problem occurs. The symptom is "table does not exist" * Looking at the query hibernate tries to run when it attempts to loadFromDatasource = it's not using the native query at all, it's making assumptions on the mapping strategy. IE: hibernate creates a very simple HQL query that selects all the properties from the entity, which obviously does not work as each property is the result of a native query joining multiple tables. * After some digging through source code, I notice that when hibernate tries to load from datasource, it's gets a persister that is a "SingleTablePersister", I believe the default. ? How can I get it to reload from the NativeQuery as defined in the @Entity? Am I using something incorrectly?
Has anyone run into this before? We are at a loss, and are about to implement our own caching - which is unfortunate we would have liked to use hibernate / ehcache.
|