From: NHibernate J. <mik...@us...> - 2007-11-18 16:22:56
|
[ http://jira.nhibernate.org/browse/NH-1090?page=3Dcom.atlassian.jira.= plugin.system.issuetabpanels:all-tabpanel ] Sergey Koshcheyev updated NH-1090: ---------------------------------- Fix Version/s: (was: 1.2.1) LATER > Query cache does not work when using Criteria API to create a projection = query with a result transformer > -------------------------------------------------------------------------= ------------------------------- > > Key: NH-1090 > URL: http://jira.nhibernate.org/browse/NH-1090 > Project: NHibernate > Issue Type: Bug > Components: Core > Affects Versions: 1.2.0.GA > Reporter: Olli Ryh=C3=A4nen > Priority: Major > Fix For: LATER > > > Enabling query-cache on a projection query with a result transformer atta= ched using Criteria API, will fail with an exception: > "System.InvalidCastException: Unable to cast object of type '<The output = type from the result transformer' to type 'System.Object[]'" > The exception is caused by the line: > "cacheable.Add( TypeFactory.Disassemble( ( object[ ] ) result[ i ], retur= nTypes, session ) );" > in "NHibernate\Cache\StandardQueryCache.cs" on line 63, when it tries to = cast the "result[i]" to an "object[]". > Using result transformers the result set has already been transformed to = the transformed type, before adding to the cache, so casting to "object[]" = will fail. (The transformation is done in the method "GetResultColumnOrRow"= in CriteriaLoader.cs on line 74, which gets called in process of loading t= he result set from the database). > To reproduce the issue, turn on caching on any of the projection query te= sts with result transformer in "CriteriaQueryTests.cs". E.g. on line 494 > IList resultWithAliasedBean =3D s.CreateCriteria(typeof (Enrolment)) > .CreateAlias("Student", "st") > .CreateAlias("Course", "co") > .SetProjection(Projections.ProjectionList() > .Add(Projections.Property("st.Name"), "studentName") > .Add(Projections.Property("co.Description"), "courseDescription"= ) > ) > .AddOrder(Order.Desc("studentName")) > .SetResultTransformer(Transformers.AliasToBean(typeof (StudentDTO))) > .SetCacheable(true) > .List(); > A simple fix would be to check if the type of "result[i]" is an "object[]= " before adding to the cache and cache non "object[]" types as is to the ca= che (and do the same check when getting the items back from the cache), but= I'm not sure if that would break the caching architecture in some way.=20 --=20 This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: htt= p://jira.nhibernate.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |