The encoding in org.hibernate.query.internal.QueryParameterBindingsImpl#generateQueryKeyMemento has a flaw in the encoding of the parameter values. A query like e.g. from Entity e where e.id in :p1 and e.id = :p2 and e.id in :p3 will show the problem. The parameters [[1],1,[1]] and [[],1,[1,1] will produce the same QueryKey.ParameterBindingsMemento even though the parameter binding is clearly different. To solve this, we must always add the count of values for multi-valued parameters into the QueryKey.ParameterBindingsMemento with e.g. mutableCacheKey.addValue(binding.getBindValues().size()). |