I’ve just found that SqmInterpretationsKey
contains this logic:
public static SqmInterpretationsKey createInterpretationsKey(InterpretationsKeySource keySource) {
if ( isCacheable ( keySource ) ) {
final Object query = CRITERIA_HQL_STRING.equals( keySource.getQueryString() )
? keySource.getSqmStatement()
: keySource.getQueryString();
return new SqmInterpretationsKey(
query,
query.hashCode(),
keySource.getResultType(),
keySource.getQueryOptions().getLockOptions(),
keySource.getQueryOptions().getTupleTransformer(),
keySource.getQueryOptions().getResultListTransformer(),
memoryEfficientDefensiveSetCopy( keySource.getLoadQueryInfluencers().getEnabledFetchProfileNames() )
);
}
else {
return null;
}
}
It means that if I am using CRITERIA query then my query it’s not cached by the queryString
but by SqmStatement
object, which generates hashcode from default java Object class. It means that hashcode is always another and this query plans are treated as different query plans. Is it bug or feature?