From e22c516b74b350171eb848ff127ce1ecf61fc0a6 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Tue, 27 Nov 2018 11:20:27 +0100 Subject: [PATCH] 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. --- src/NHibernate/Engine/Query/QueryPlanCache.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/NHibernate/Engine/Query/QueryPlanCache.cs b/src/NHibernate/Engine/Query/QueryPlanCache.cs index 6a0c0b6a7ee..01849f96e77 100644 --- a/src/NHibernate/Engine/Query/QueryPlanCache.cs +++ b/src/NHibernate/Engine/Query/QueryPlanCache.cs @@ -196,20 +196,23 @@ private class HQLQueryPlanKey : IEquatable, IDeserializationCal // hashcode may vary among processes, they cannot be stored and have to be re-computed after deserialization [NonSerialized] private int? _hashCode; + + private readonly System.Type queryType; private readonly System.Type queryTypeDiscriminator; public HQLQueryPlanKey(string query, bool shallow, IDictionary enabledFilters) - : this(typeof(object), query, shallow, enabledFilters) + : this(typeof(object), typeof(object), query, shallow, enabledFilters) { } public HQLQueryPlanKey(IQueryExpression queryExpression, bool shallow, IDictionary enabledFilters) - : this(queryExpression.GetType(), queryExpression.Key, shallow, enabledFilters) + : this(queryExpression.Type, queryExpression.GetType(), queryExpression.Key, shallow, enabledFilters) { } - protected HQLQueryPlanKey(System.Type queryTypeDiscriminator, string query, bool shallow, IDictionary enabledFilters) + protected HQLQueryPlanKey(System.Type queryType, System.Type queryTypeDiscriminator, string query, bool shallow, IDictionary enabledFilters) { + this.queryType = queryType; this.queryTypeDiscriminator = queryTypeDiscriminator; this.query = query; this.shallow = shallow; @@ -255,6 +258,11 @@ public bool Equals(HQLQueryPlanKey that) return false; } + if (queryType != that.queryType) + { + return false; + } + if (queryTypeDiscriminator != that.queryTypeDiscriminator) { return false; @@ -285,6 +293,7 @@ private int GenerateHashCode() var hash = query.GetHashCode(); hash = 29 * hash + (shallow ? 1 : 0); hash = 29 * hash + CollectionHelper.GetHashCode(_filterNames); + hash = 29 * hash + queryType.GetHashCode(); hash = 29 * hash + queryTypeDiscriminator.GetHashCode(); return hash; }