-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: A problem with query cache when using result transformers
PostPosted: Fri Aug 10, 2007 3:01 am 
Newbie

Joined: Fri Aug 10, 2007 2:12 am
Posts: 1
Hibernate version: Latest from the SVN repository trunk (revision 2927)

Hi,

I am using the latest development version from the trunk, but I assume the problem affects 1.2 version as well.

Enabling query-cache on a projection query with a result transformer attached 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:
Code:
cacheable.Add( TypeFactory.Disassemble( ( object[ ] ) result[ i ], returnTypes, 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 the result set from the database).

To reproduce the issue, turn on caching on any of the projection query tests with result transformer in "CriteriaQueryTests.cs". E.g. on line 494
Code:
IList resultWithAliasedBean = 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();


I am not sure if this is by design or a bug, but I though I'd report it anyway. At least I didn't find anything in the documentation implying that query cache shouldn't work in this situation.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 3:13 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, it's a bug. Please submit it to JIRA.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.