-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hibernate bug for query cache
PostPosted: Fri Dec 09, 2011 1:24 am 
Newbie

Joined: Tue Apr 08, 2008 2:40 am
Posts: 5
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.