最近、NHibernate 3.3 を使用するようにアプリをアップグレードし、キャッシュを有効にしたいと考えました。
私たちはマルチテナント環境にいるので、各セッション ファクトリが各クライアントのリージョンを保持するようにします。
これが私のNHibernate構成です:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="cache.use_query_cache">true</property>
<property name="cache.use_second_level_cache">true</property>
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider,NHibernate.Caches.SysCache</property>
<property name="connection.connection_string">Data Source=localhost; database=test;user=test; password=test;</property>
<property name="show_sql">false</property>
<property name="command_timeout">1000</property>
</session-factory>
</hibernate-configuration>
そして私たちのセッションファクトリージェネレーターでは...
private static ISessionFactory GetSessionFactory(string connectionString, string driverClass = NormDriverClass, string prefix = null)
{
Configuration configuration = new Configuration();
configuration.Configure().SetProperty(ConnectionStringProperty, connectionString);
configuration.Properties.Add(ConnectionDriverProperty, driverClass);
configuration.Properties.Add("regionPrefix", prefix ?? "default");
configuration.AddAssembly(typeof(Foo).Assembly);
return configuration.BuildSessionFactory();
}
クエリをキャッシュ可能に設定しました。
query.SetCacheable(true).SetCacheMode(CacheMode.Normal);
毎回次のエラーが表示されます
System.IndexOutOfRangeException : Index was outside the bounds of the array.
at NHibernate.Type.TypeHelper.Disassemble(Object[] row, ICacheAssembler[] types, Boolean[] nonCacheable, ISessionImplementor session, Object owner)
at NHibernate.Cache.StandardQueryCache.Put(QueryKey key, ICacheAssembler[] returnTypes, IList result, Boolean isNaturalKeyLookup, ISessionImplementor session)
at NHibernate.Loader.Loader.PutResultInQueryCache(ISessionImplementor session, QueryParameters queryParameters, IType[] resultTypes, IQueryCache queryCache, QueryKey key, IList result)
at NHibernate.Loader.Loader.ListUsingQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
at NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results)
at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results)
at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
at NHibernate.Impl.SqlQueryImpl.List()
キャッシュプロバイダーのせいだと思って、元に戻しました
<property name="cache.provider_class">NHibernate.Cache.HashtableCacheProvider,NHibernate</property>
変化なし。
リージョン プレフィックス コードを削除しましたが、変更はありません。
「Use_query_cache」を false に設定すると、ランタイム例外は修正されますが、キャッシュは使用されません。