i found the bug for query cache for example:
table : Dept fields: dept_name(varchar) dept_type(int) dept_order(int)
data: dept_name dept_type dept_order dept1 1 0 dept2 1 0
the query: 1 query List list = session.createQuery("select p1 from Dept as p1 where p1.dept_type = :deptType and p1.dept_order = :deptOrder") .setInteger("deptType" , 1).setInteger("deptOrder" , 0).setCacheable(true).setCacheRegion("Dept).list() System.out.println(list.size); 2 query:
list = session.createQuery("select p1 from Dept as p1 where p1.dept_type = :deptType and p1.dept_order = :deptOrder") .setInteger("deptType" , 0).setInteger("deptOrder" , 1).setCacheable(true).setCacheRegion("Dept).list() System.out.println(list.size);
the out result: 1 1 1 1 the actual result is: 1 1 0 0 i trance the code i find the org.hibernate.cache.QueryKey
private int generateHashCode() { int result = 13; result = 37 * result + (firstRow != null ? firstRow.hashCode() : 0); result = 37 * result + (maxRows != null ? maxRows.hashCode() : 0); for(int i = 0; i < positionalParameterValues.length; i++) result = 37 * result + (positionalParameterValues[i] != null ? positionalParameterTypes[i].getHashCode(positionalParameterValues[i], entityMode) : 0);
result = 37 * result + (namedParameters != null ? namedParameters.hashCode() : 0); result = 37 * result + (filterKeys != null ? filterKeys.hashCode() : 0); result = 37 * result + (customTransformer != null ? customTransformer.hashCode() : 0); result = 37 * result + sqlQueryString.hashCode(); return result; }
namedParameters.hashCode() the hashCode is same
for example: Map map = new HashMap(); map.put("dept_type" , 0 ); map.put("dept_order" ,1); System.out.println(map.hashCode()); map = new HashMap(); map.put("dept_type" , 1 ); map.put("dept_order" ,0); System.out.println(map.hashCode());
the out result: 107958673 107958673
also the query parameter value is different but the map hashCode is same so the 1 query 2 query query cache key is same
|