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.  [ 1 post ] 
Author Message
 Post subject: MultiQuery(Impl) and ResultTransformer
PostPosted: Thu Sep 06, 2007 5:24 pm 
Newbie

Joined: Thu Sep 06, 2007 4:26 pm
Posts: 1
Summary: MutliQueryImpl applies resultTransformer to the list of query result collections, instead of at the entity/row level.

Hibernate version: 1.2.0.GA (and r2972)

Mapping documents: NA

Code between sessionFactory.openSession() and session.close():

Code:
        IMultiQuery mq = session.CreateMultiQuery();
        for (int i = 0; i < ZoneArray.Length; ++i)
        {
            string z = ZoneArray[i];
            IQuery q = session.CreateQuery(string.Format(
                @"

select q
from Question q
    join q.PostDefaultPageList pdp
    join pdp.Page as page
    left join fetch q.PostLocationList pl
    left join fetch pl.WebsitePage wp
    left join fetch wp.Page
    left join fetch wp.Website
where
    q.SystemOnly = true
    and page.Key = :page
    and pdp.DefaultPageZone = :zone{0}
order by pdp.DefaultPageOrder

", i))
                .SetString("zone" + i, z);
            mq.Add(q);
        }
        mq.SetResultTransformer(CriteriaUtil.DistinctRootEntity);
        mq.SetString("page", PageKey);
        _results = mq.List();


Name and version of the database you are using: Sql Server 2005

The generated SQL (show_sql=true): You asked for it:

Code:
select question0_.post_id as post1_23_0_, websitepag4_.websitePage_id as websiteP1_11_1_, page5_.page_id as page1_30_2_, postlocati3_.postLocation_id as postLoca1_22_3_, website6_.website_id as website1_34_4_, question0_.questiontype_id as question2_24_0_, question0_.questionValueType_id as question3_24_0_, question0_.question_required as question4_24_0_, question0_.question_responseLimitValue as question5_24_0_, question0_.responseLimitType_id as response6_24_0_, question0_.question_updateLimitValue as question7_24_0_, question0_.update_responseLimitType_id as update8_24_0_, question0_.question_validateRegex as question9_24_0_, question0_.question_classStorage as question10_24_0_, question0_.question_askOptionsInstead as question11_24_0_, question0_1_.website_id as website2_23_0_, question0_1_.postType_id as postType3_23_0_, question0_1_.post_text as post4_23_0_, question0_1_.post_date as post5_23_0_, question0_1_.post_status as post6_23_0_, question0_1_.parent_post_id as parent7_23_0_, question0_1_.post_systemOnly as post8_23_0_, websitepag4_.website_id as website2_11_1_, websitepag4_.page_id as page3_11_1_, websitepag4_.defaultContent_id as defaultC4_11_1_, websitepag4_.websitePage_html as websiteP5_11_1_, page5_.page_name as page2_30_2_, page5_.page_key as page3_30_2_, page5_.page_required as page4_30_2_, page5_.page_order as page5_30_2_, page5_.page_canEdit as page6_30_2_, page5_.page_showInMenu as page7_30_2_, page5_.page_authenticate as page8_30_2_, postlocati3_.post_id as post2_22_3_, postlocati3_.websitePage_id as websiteP3_22_3_, postlocati3_.postLocation_order as postLoca4_22_3_, postlocati3_.postLocation_zone as postLoca5_22_3_, website6_.parentWebsite_Id as parentWe2_34_4_, website6_.website_name as website3_34_4_, website6_.website_subName as website4_34_4_, website6_.website_shortName as website5_34_4_, website6_.website_numberOfEmployees as website6_34_4_, website6_.website_phone as website7_34_4_, website6_.website_email as website8_34_4_, website6_.website_otherUrl as website9_34_4_, website6_.template_id as template10_34_4_, website6_.illustration_id as illustr11_34_4_, website6_.website_illustrationStyle as website12_34_4_, website6_.website_keyPartner_contact_id as website13_34_4_, website6_.website_outreach_contact_id as website14_34_4_, website6_.website_CreateDate as website15_34_4_, website6_.website_numCommuteLogDays as website16_34_4_, postlocati3_.post_id as post2___0__, postlocati3_.postLocation_id as postLoca1_0__

from Question question0_ inner join Post question0_1_ on question0_.post_id=question0_1_.post_id inner join PostDefaultPage postdefaul1_ on question0_.post_id=postdefaul1_.post_id inner join Page page2_ on postdefaul1_.page_id=page2_.page_id left outer join PostLocation postlocati3_ on question0_.post_id=postlocati3_.post_id left outer join WebsitePage websitepag4_ on postlocati3_.websitePage_id=websitepag4_.websitePage_id left outer join Page page5_ on websitepag4_.page_id=page5_.page_id left outer join Website website6_ on websitepag4_.website_id=website6_.website_id

where (question0_1_.post_systemOnly=1 )and(page2_.page_key=? )and(postdefaul1_.defaultPage_zone=? ) order by  postdefaul1_.defaultPage_order

select question0_.post_id as post1_23_0_, websitepag4_.websitePage_id as websiteP1_11_1_, page5_.page_id as page1_30_2_, postlocati3_.postLocation_id as postLoca1_22_3_, website6_.website_id as website1_34_4_, question0_.questiontype_id as question2_24_0_, question0_.questionValueType_id as question3_24_0_, question0_.question_required as question4_24_0_, question0_.question_responseLimitValue as question5_24_0_, question0_.responseLimitType_id as response6_24_0_, question0_.question_updateLimitValue as question7_24_0_, question0_.update_responseLimitType_id as update8_24_0_, question0_.question_validateRegex as question9_24_0_, question0_.question_classStorage as question10_24_0_, question0_.question_askOptionsInstead as question11_24_0_, question0_1_.website_id as website2_23_0_, question0_1_.postType_id as postType3_23_0_, question0_1_.post_text as post4_23_0_, question0_1_.post_date as post5_23_0_, question0_1_.post_status as post6_23_0_, question0_1_.parent_post_id as parent7_23_0_, question0_1_.post_systemOnly as post8_23_0_, websitepag4_.website_id as website2_11_1_, websitepag4_.page_id as page3_11_1_, websitepag4_.defaultContent_id as defaultC4_11_1_, websitepag4_.websitePage_html as websiteP5_11_1_, page5_.page_name as page2_30_2_, page5_.page_key as page3_30_2_, page5_.page_required as page4_30_2_, page5_.page_order as page5_30_2_, page5_.page_canEdit as page6_30_2_, page5_.page_showInMenu as page7_30_2_, page5_.page_authenticate as page8_30_2_, postlocati3_.post_id as post2_22_3_, postlocati3_.websitePage_id as websiteP3_22_3_, postlocati3_.postLocation_order as postLoca4_22_3_, postlocati3_.postLocation_zone as postLoca5_22_3_, website6_.parentWebsite_Id as parentWe2_34_4_, website6_.website_name as website3_34_4_, website6_.website_subName as website4_34_4_, website6_.website_shortName as website5_34_4_, website6_.website_numberOfEmployees as website6_34_4_, website6_.website_phone as website7_34_4_, website6_.website_email as website8_34_4_, website6_.website_otherUrl as website9_34_4_, website6_.template_id as template10_34_4_, website6_.illustration_id as illustr11_34_4_, website6_.website_illustrationStyle as website12_34_4_, website6_.website_keyPartner_contact_id as website13_34_4_, website6_.website_outreach_contact_id as website14_34_4_, website6_.website_CreateDate as website15_34_4_, website6_.website_numCommuteLogDays as website16_34_4_, postlocati3_.post_id as post2___0__, postlocati3_.postLocation_id as postLoca1_0__ from Question question0_ inner join Post question0_1_ on question0_.post_id=question0_1_.post_id inner join PostDefaultPage postdefaul1_ on question0_.post_id=postdefaul1_.post_id inner join Page page2_ on postdefaul1_.page_id=page2_.page_id left outer join PostLocation postlocati3_ on question0_.post_id=postlocati3_.post_id left outer join WebsitePage websitepag4_ on postlocati3_.websitePage_id=websitepag4_.websitePage_id left outer join Page page5_ on websitepag4_.page_id=page5_.page_id left outer join Website website6_ on websitepag4_.website_id=website6_.website_id where (question0_1_.post_systemOnly=1 )and(page2_.page_key=? )and(postdefaul1_.defaultPage_zone=? ) order by  postdefaul1_.defaultPage_order




Debug level Hibernate log excerpt:

DEBUG 2007-09-06 15:10:37,603 1496828ms ntityResultTransformer TransformList - transformed: 3 rows to: 3 distinct results

Note: this line is for the case of ZoneArray.Length == 3 in the code above

The bug lives here: MultiQueryImpl.GetResultList(IList results)
Code:
        protected virtual IList GetResultList(IList results)
        {
            if (resultTransformer == null)
                return results;

            return resultTransformer.TransformList(results);
        }

should be something like:
Code:
        protected virtual IList GetResultList(IList results)
        {
-            if (resultTransformer == null)
+            if (resultTransformer != null)
+               for (int i=0,len=results.Count;i<len;++i)
+                   results[i] = resultTransformer.TransformList((IList)results[i]);
            return results;
        }




Unless I missed something....


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

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.