| Hibernate performs useless class lookup when applying the constant conversion. For instance, in the query SELECT p FROM Event p WHERE p.eventstart<?1, there will be a class lookup for ch.astorm.entities.Event and for p.eventstart and this will occur each time the query needs to be compiled by Hibernate. There will be a warning in the logs just as mentioned in the issue
HHH-11245 Open . The "randomess" describe in
HHH-11243 Open is caused by query plan caching (see
HHH-4627 Closed ). Hence, to reproduce the warning systematically, a "new" query needs to be given to Hibernate, which is somewhat easy if they are not parametrized. So, I set the property hibernate.query.plan_cache_max_size to 40 (which will be the minimum accepted value because of the BoundedConcurrentHashMap fixed parameters created in QueryPlanCache) and created a simple loop in each query to force renewal of the cache:
entityManager.createQuery("SELECT p FROM Event p WHERE p.eventstart<=?1 AND p.eventend>=?2", Event.class);
for(int qp=0 ; qp<40 ; ++qp) {
entityManager.createQuery("SELECT p FROM Event p WHERE 0="+qp);
}
My patch suggests transforming the method handleDotStructure in QueryTranslatorImpl (line 613) to:
private void handleDotStructure(AST dotStructureRoot) {
final String expression = ASTUtil.getPathText( dotStructureRoot );
final Object entity = factory.getMetamodel().entity( expression );
if( entity == null && expression.indexOf('.') != -1 ) { }
}
This check will avoid entity lookups (because the expression ch.astorm.entities.Event will cause a lookup on ch.astorm.entities which will be always null), but the patterns like p.eventstart will still cause IMHO a useless lookup which could probably be avoided by using the parsed HQL query. Any suggestion is welcome. Thanks in advance. |