-->
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: HQL Outer Join Different Behavior from Previous Version
PostPosted: Mon Oct 03, 2011 1:11 pm 
Newbie

Joined: Wed Sep 17, 2003 5:36 pm
Posts: 5
Hi guys,

I have been running the HQL query below for ages and it was working fine until I upgraded to v3.6.6. The problem is the SQL being generated for the outer join. The correct SQL should only outer join the InvoiceGroup table. However, v3.6.6 generated a SQL that not only outer join the InvoiceGroup table but also inner join it again. I have attached both the HQL and the generated SQL.

Am I not constructing the HQL correctly or is this a possible bug that was introduced in later version?

Thanks in advance for any insights,
Ben

Code:
    select ro.customer,
           rp.invoiceGroup,
           ro.reportProgram
      from ReportOrder ro
      join ro.reports r
      join ro.reportProgram rp
left join rp.invoiceGroup
     where r.isLatest = true
       and r.reportStatusCode <> :reportStatusCode
       and ro.pricingDate >= :startingPricingDate
       and ro.pricingDate < :endingPricingDate
       and (not (r.sendToPrinter = false and ro.chargeType = :noChargeType))
     group by ro.customer, ro.reportProgram
     order by ro.customer, rp.invoiceGroup, ro.reportProgram


Generated SQL:

Code:
select
   customer4_.ID                               as ID81_0_,
   invoicegro5_.ID                             as ID18_1_,
   reportprog6_.ID                             as ID14_2_,
   customer4_.Version                          as Version81_0_,
   customer4_.Name                             as Name81_0_,
   customer4_.Parent_ID                        as Parent4_81_0_,
   customer4_.IsActive                         as IsActive81_0_,
   customer4_.DealerID                         as DealerID81_0_,
   customer4_.AE                               as AE81_0_,
   customer4_.CreatedDate                      as CreatedD8_81_0_,
   customer4_.CreatedBy                        as CreatedBy81_0_,
   customer4_.UpdatedDate                      as Updated10_81_0_,
   customer4_.UpdatedBy                        as UpdatedBy81_0_,
   invoicegro5_.Version                        as Version18_1_,
   invoicegro5_.GroupCode                      as GroupCode18_1_,
   invoicegro5_.GroupName                      as GroupName18_1_,
   invoicegro5_.InvoiceByPackingList           as InvoiceB5_18_1_,
   invoicegro5_.CreatedDate                    as CreatedD6_18_1_,
   invoicegro5_.CreatedBy                      as CreatedBy18_1_,
   invoicegro5_.UpdatedDate                    as UpdatedD8_18_1_,
   invoicegro5_.UpdatedBy                      as UpdatedBy18_1_,
   reportprog6_.Version                        as Version14_2_,
   reportprog6_.Customer_ID                    as Customer3_14_2_,
   reportprog6_.Customer_ProductPrefix_ID      as Customer4_14_2_,
   reportprog6_.Seller_ID                      as Seller5_14_2_,
   reportprog6_.SellerCode                     as SellerCode14_2_,
   reportprog6_.Description                    as Descript7_14_2_,
   reportprog6_.CanSetExpire                   as CanSetEx8_14_2_,
   reportprog6_.IsTotalWeightRequired          as IsTotalW9_14_2_,
   reportprog6_.IsSKURequired                  as IsSKURe10_14_2_,
   reportprog6_.UseLabDataFromScan             as UseLabD11_14_2_,
   reportprog6_.UseProductIDInFilename         as UseProd12_14_2_,
   reportprog6_.UseCustomerDefaultShipAddress  as UseCust13_14_2_,
   reportprog6_.DefaultShipAddress_ID          as Default14_14_2_,
   reportprog6_.DoNotCheckForIncompleteLabData as DoNotCh15_14_2_,
   reportprog6_.FTPProfile_ID                  as FTPProfile16_14_2_,
   reportprog6_.ReportBarColor_ID              as ReportB17_14_2_,
   reportprog6_.InvoiceGroup_ID                as Invoice18_14_2_,
   reportprog6_.InvoiceByPackingList           as Invoice19_14_2_,
   reportprog6_.CreatedDate                    as Created20_14_2_,
   reportprog6_.CreatedBy                      as CreatedBy14_2_,
   reportprog6_.UpdatedDate                    as Updated22_14_2_,
   reportprog6_.UpdatedBy                      as UpdatedBy14_2_
from ReportOrder reportorde0_
   inner join Report reports1_
     on reportorde0_.ID = reports1_.ReportOrder_ID
     
   inner join ReportProgram reportprog2_
     on reportorde0_.ReportProgram_ID = reportprog2_.ID
     
   left outer join InvoiceGroup invoicegro3_
     on reportprog2_.InvoiceGroup_ID = invoicegro3_.ID
     
   inner join InvoiceGroup invoicegro5_
     on reportprog2_.InvoiceGroup_ID = invoicegro5_.ID
     
   inner join core.customer customer4_
     on reportorde0_.Customer_ID = customer4_.ID
     
   inner join ReportProgram reportprog6_
     on reportorde0_.ReportProgram_ID = reportprog6_.ID
     
where reports1_.IsLatest = 1
     and reports1_.ReportStatusCode <> ?
     and reportorde0_.PricingDate >= ?
     and reportorde0_.PricingDate < ?
     and (reports1_.SendToPrinter <> 0 or reportorde0_.ChargeTypeCode <> ?)
group by reportorde0_.Customer_ID, reportorde0_.ReportProgram_ID
order by reportorde0_.Customer_ID, reportprog2_.InvoiceGroup_ID, reportorde0_.ReportProgram_ID


Top
 Profile  
 
 Post subject: Re: HQL Outer Join Different Behavior from Previous Version
PostPosted: Mon Oct 03, 2011 3:41 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think this could be related to the bug described in http://opensource.atlassian.com/project ... e/HHH-4091

The issue in your query is probably that the rp.invoiceGroup in the select and order by parts is creating an extra implicit join. To avoid it, you should assign an alias to left join rp.invoiceGroup and use that alias in the other places. There is a similar issue with ro.reportProgram which is also joined twice.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.