SetCacheable throws IndexOutOfBoundsException

I have the following query in NHibernate where the result is a list of DTOs, not entities:

var result = query
                //.SetCacheable(true)
                .SetResultTransformer(new MyDTOTransformer())
                .List<DTO>();

This works with SetCacheable in the comment, but it throws an IndexOutOfBoundsException when I set SetCacheable to true.

This is stacktrace:

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 ...

Can someone help me and say how can I fix this (or even if it is supported on NHibernate)?

I am currently using NHibernate version 2.1.0.4000.

Thanks Elle

+3
source share
3 answers

, , , . , , , - , / ( , , 1 ).

nhibernate, , , , ,

+1

, . , , SetCacheable , IndexOutOfBoundsException.

, , . query.setCacheable(true); query.setCacheMode(CacheMode.GET);, ! .

0

, "" , DTO, AddScalar. AddScalar ( ) , (, , )

Just use AddScalar to display all returned columns, and I bet it works.

var result = query
            //.SetCacheable(true)
            .AddScalar("yourfirstcolumn",NHibernateUtil.Int32)
            .AddScalar("yoursecondcolumn",NHibernateUtil.String)
            .SetResultTransformer(new MyDTOTransformer())
            .List<DTO>();
0
source

Source: https://habr.com/ru/post/1753696/


All Articles