我在NHibernate中有以下查询,其中的结果是DTO的列表,而不是实体:
var result = query
//.SetCacheable(true)
.SetResultTransformer(new MyDTOTransformer())
.List<DTO>();
这在注释中可与SetCacheable一起使用,但是当我将SetCacheable设置为true时,它将引发IndexOutOfBoundsException。
这是堆栈跟踪:
at NHibernate.Type.TypeFactory.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.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
at NHibernate.Loader.Custom.CustomLoader.List(ISessionImplementor session, QueryParameters queryParameters)
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[T](NativeSQLQuerySpecification spec, QueryParameters queryParameters)
at NHibernate.Impl.SqlQueryImpl.List[T]()
at ...
谁能帮助我,说我该如何解决(甚至NHibernate支持)?
我目前正在使用NHibernate版本2.1.0.4000。
谢谢,
耶勒
最佳答案
我可能会弄错,但是我认为查询缓存依赖于启用的第二级缓存。老实说,我想知道如果没有实体缓存在第二级缓存中是否会有用,因为它存储的只是与给定查询/参数组合关联的ID列表(您仍然需要转到数据库以实际获取对象,在某些情况下,这可能导致每个对象进行1次查询)。
This是我所见过的nhibernate中关于缓存的更好的帖子之一,似乎暗示到最后,您只能在第二级缓存中缓存查询
关于nhibernate - SetCacheable抛出IndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3203098/