Hi all, fairly new to hibernate so please be kind!
In short, have query caching switched on, and am creating and running named queries, expecting a second invocation of the same named query with the same parameter to hit the cache. However, the cache is 'missed' (looks like cache is keyed on SQL) ?
Am using ehcache 1.7.0 Core and hibernate core 3.3.1 GA
It appears as if the SQL generated for the second invocation has different column alias names:
debug from org.hibernate.hql.ast.QueryTranslatorImpl:
e.g. first invocation of HQL query: HQL: FROM net.x.cdm.C c where c.cName = :name SQL: select c0_.c_id as c1_3_, c0_.cName as cName3_ from schema.c c0_ where c0_.cName=?
Latter invocation: HQL: FROM net.x.cdm.C c where c.cName = :name SQL: select c0_.c_id as c1_8_, c0_.cName as cName3_ from schema.c c0_ where c0_.cName=?
Note that each invocation creates the query afresh (as have different EntityManagers, different threads - no racing though)
final Query qu = em.createNamedQuery("getCByName");
and am defining getCByName as an annotation on the entity net.x.cdm.C (And also tried in orm.xml).
Is there any way to either 'influence' the HQL->SQL translation to be deterministic in column naming, or to have the standard query cache to key on HQL rather than the generated SQL??!?
Thanks for any help in advance,
Michael Beale
|