2012-09-24 65 views
1

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

回答

0

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

我在Jira上创建了issue,刚刚意识到其他人在几个月前完成了same

+0

我已经通过工作和原来公共类CustomLoader:装载机 \t { \t \t //目前*不*被缓存,如果自动发现类型是影响(如“选择* ...”) 应该有给我打翻了。 也就是说,我已经开始工作了,看起来我会为这个问题修复。它需要更多的测试,但我会留下另一条评论并链接到Github Fork上。 – ClutchDude

+0

@ClutchDude:酷。让我知道,因为我仍然在为这个问题而努力。 – LeftyX

+0

我已经完成了一个初步修复。我将在下周清理它并进行更多测试。一旦足够稳定,我会做一个拉动请求。 https://github.com/Seakip18/nhibernate-core/tree/Branch_3.3.2GA_CacheFix – ClutchDude