1

我最近升级了我们的应用程序以使用 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 可修复运行时异常,但随后不使用缓存。

4

1 回答 1

0

这里同样的问题。我已经下载了源代码并进行了一些调试,问题似乎出在核心模块中。

我在 Jira 上创建了一个问题,并且刚刚意识到几个月前其他人也做了同样的事情。

于 2012-10-30T10:03:44.603 回答