Using thoses JPA properties
props.put( "hibernate.cache.use_query_cache", "true" );
props.put( "hibernate.cache.use_second_level_cache", "true" );
props.put("hibernate.temp.use_jdbc_metadata_defaults", "false");
props.put( "hibernate.cache.region.factory_class", "org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" );
props.put( "javax.persistence.sharedCache.mode", SharedCacheMode.ALL );
Ehcache is not efficient for the same query,
Problem is related to function namedParameters.hashCode() of QueryCache class, it generates a different HashCode for the same query !
private int generateHashCode() {
int result = 13;
result = 37 * result + ( firstRow==null ? 0 : firstRow.hashCode() );
result = 37 * result + ( maxRows==null ? 0 : maxRows.hashCode() );
for ( int i=0; i< positionalParameterValues.length; i++ ) {
result = 37 * result + ( positionalParameterValues[i]==null ? 0 : positionalParameterTypes[i].getHashCode( positionalParameterValues[i] ) );
}
result = 37 * result + ( namedParameters==null ? 0 : namedParameters.hashCode() );
result = 37 * result + ( filterKeys ==null ? 0 : filterKeys.hashCode() );
result = 37 * result + ( customTransformer==null ? 0 : customTransformer.hashCode() );
result = 37 * result + ( tenantIdentifier==null ? 0 : tenantIdentifier.hashCode() );
result = 37 * result + sqlQueryString.hashCode();
return result;
}
which is related to the Class
org.hibernate.type.AbstractType
public int getHashCode(Object x) {
return x.hashCode();
}
it generates a different (new) hachCode for the same Array object [01, 1] !
This hashCode method should be recursive for Arrays
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…