-->
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.  [ 6 posts ] 
Author Message
 Post subject: Named parameters not taking into account in query cache.
PostPosted: Wed Apr 25, 2007 8:08 am 
Beginner
Beginner

Joined: Fri Jan 19, 2007 10:45 am
Posts: 23
Hello, I'm using NH1.2RC2
Named parameters values are not taking into account is the Query Cache.
If 2 queries only differs by the value on the named paramters, then only one key is created in the Query Cache.

In the source code (QueryKey.cs, Method ComputeHashCode()) we see that the code that handle values of named parameters has been commented out.

Is there a reason ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 8:58 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Not sure why you think only one cache key is created. The fact that these two queries have equal hash code doesn't affect anything, it's just inefficient.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 9:42 am 
Beginner
Beginner

Joined: Fri Jan 19, 2007 10:45 am
Posts: 23
sergey wrote:
Not sure why you think only one cache key is created. The fact that these two queries have equal hash code doesn't affect anything, it's just inefficient.



Here is the modification I add to do to make it work...
Do you agree with me ? If the 2 queries differs only by the value of their namedParameters, then they both have the same sqlQueryString. But in fact, it is 2 differents queries, that should have each one an entry in the Cache Query...

public int ComputeHashCode()
{
unchecked
{
int result = 13;
result = 37 * result + firstRow.GetHashCode();
result = 37 * result + maxRows.GetHashCode();


// NH - commented this out, namedParameters don't have a useful GetHashCode implementations
//result = 37 * result
// + ( namedParameters == null ? 0 : namedParameters.GetHashCode() );

// SGH ADDED
foreach (DictionaryEntry entry in namedParameters)
{
result = 37 * result + (entry.Value == null ? 0 : entry.Value.GetHashCode());
}
// SGH END


for (int i = 0; i < types.Length; i++)
{
result = 37 * result + (types[i] == null ? 0 : types[i].GetHashCode());
}
for (int i = 0; i < values.Length; i++)
{
result = 37 * result + (values[i] == null ? 0 : values[i].GetHashCode());
}

if (filters != null)
{
foreach (object filter in filters)
{
result = 37 * result + filter.GetHashCode();
}
}

result = 37 * result + (customTransformer == null ? 0 : customTransformer.GetHashCode());
result = 37 * result + sqlQueryString.GetHashCode();
return result;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 5:10 am 
Beginner
Beginner

Joined: Fri Jan 19, 2007 10:45 am
Posts: 23
Do you agree with the change in red ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 5:37 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, why not. But I will be very very very surprised if it actually solves your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 8:05 am 
Beginner
Beginner

Joined: Fri Jan 19, 2007 10:45 am
Posts: 23
Ok, I understand why I would be very vers surprised
In fact, as you told me in an other post, even if the 2 QueryKeys have the same HashCode, it's finally the Equals method that is used to find the right instance amoung all instances that have the HashCode we are looking for...

In the code, the QueryKey.Equals() take into account the values of the named parameters... so it work without anychange.

Thanks for your help sergey.


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

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.