Skip to content

Commit 5cc4e96

Browse files
author
Erik Schilling
committed
Discriminate query plan caches by the assembly depending return type
When having multiple assemblies with the same type (this can happen when dynamically generating assemblies or loading assemblies multiple times), NHibernate used to return query plan cache entries with mismatching types. The query portion of the cache key contained the type, but not the assembly. Thus two types from different assemblies, but with the same name lead to returning plans with wrong return types.
1 parent fa978cf commit 5cc4e96

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/NHibernate/Engine/Query/QueryPlanCache.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,23 @@ private class HQLQueryPlanKey : IEquatable<HQLQueryPlanKey>, IDeserializationCal
196196
// hashcode may vary among processes, they cannot be stored and have to be re-computed after deserialization
197197
[NonSerialized]
198198
private int? _hashCode;
199+
200+
private readonly System.Type queryType;
199201
private readonly System.Type queryTypeDiscriminator;
200202

201203
public HQLQueryPlanKey(string query, bool shallow, IDictionary<string, IFilter> enabledFilters)
202-
: this(typeof(object), query, shallow, enabledFilters)
204+
: this(typeof(object), typeof(object), query, shallow, enabledFilters)
203205
{
204206
}
205207

206208
public HQLQueryPlanKey(IQueryExpression queryExpression, bool shallow, IDictionary<string, IFilter> enabledFilters)
207-
: this(queryExpression.GetType(), queryExpression.Key, shallow, enabledFilters)
209+
: this(queryExpression.Type, queryExpression.GetType(), queryExpression.Key, shallow, enabledFilters)
208210
{
209211
}
210212

211-
protected HQLQueryPlanKey(System.Type queryTypeDiscriminator, string query, bool shallow, IDictionary<string, IFilter> enabledFilters)
213+
protected HQLQueryPlanKey(System.Type queryType, System.Type queryTypeDiscriminator, string query, bool shallow, IDictionary<string, IFilter> enabledFilters)
212214
{
215+
this.queryType = queryType;
213216
this.queryTypeDiscriminator = queryTypeDiscriminator;
214217
this.query = query;
215218
this.shallow = shallow;
@@ -255,6 +258,11 @@ public bool Equals(HQLQueryPlanKey that)
255258
return false;
256259
}
257260

261+
if (queryType != that.queryType)
262+
{
263+
return false;
264+
}
265+
258266
if (queryTypeDiscriminator != that.queryTypeDiscriminator)
259267
{
260268
return false;
@@ -285,6 +293,7 @@ private int GenerateHashCode()
285293
var hash = query.GetHashCode();
286294
hash = 29 * hash + (shallow ? 1 : 0);
287295
hash = 29 * hash + CollectionHelper.GetHashCode(_filterNames);
296+
hash = 29 * hash + queryType.GetHashCode();
288297
hash = 29 * hash + queryTypeDiscriminator.GetHashCode();
289298
return hash;
290299
}

0 commit comments

Comments
 (0)