I have an HQL query:
Code:
"SELECT DISTINCT ir.id, ir.weeksToPromoteStart, ir.weeksToPromoteStart, ir.auditInfo,"
+ " ir.risk, ir.item.itemUPC, ir.item.itemName, ir.item.top20, ir.item.itemSize, ir.item.itemPack, ir.costs.trend,"
+ " ir.costs.currentCostRange.lowCost, ir.costs.currentCostRange.highCost,"
+ " ir.costs.projectedCostRange.lowCost, ir.costs.projectedCostRange.highCost, ir.costs.currentCostsLastUpdated,"
+ " ir.item.subCommodity.comp_id.commodity.description, ir.item.subCommodity.description, ir.fieldOffice.name, ir.comments.comments, "
+ " ir.growingRegions.elements, ir.available "
+ " FROM ItemReport as ir left join ir.growingRegions.elements as gr where 1 = 1"
+
" ORDER BY ir.item.subCommodity.description, ir.item.subCommodity.comp_id.commodity.description, ir.item.itemUPC, ir.id ";
There are multiple other criteria added to the where clause (hence the 1=1).
ItemReport has a M:1 with Item, a M:1 with Field Office, 1:1 with Costs, 1:1 with Comments, 1:M with Photos and 1:M with Growing Regions.
When I run my code, the SQL generated yields:
Code:
select distinct itemrepo0_.itm_rpt_id as x0_0_, itemrepo0_.wek_too_pro_stt_dt as x1_0_, itemrepo0_.wek_too_pro_stt_dt as x2_0_, itemrepo0_.lst_upd_ts as x3_0_, itemrepo0_.crt_ts as x3_1_, itemrepo0_.upd_usr_id as x3_2_, itemrepo0_.crt_usr_id as x3_3_, itemrepo0_.ris_cd as x4_0_, item3_.itm_upc_cd as x5_0_, item3_.itm_nam_tx as x6_0_, item3_.top_020_cd as x7_0_, item3_.itm_siz_tx as x8_0_, item3_.itm_pak_qy as x9_0_, costs6_.ted_cd as x10_0_, costs6_.cur_low_cst_am as x11_0_, costs6_.cur_hgh_cst_am as x12_0_, costs6_.pjt_low_cst_am as x13_0_, costs6_.pjt_hgh_cst_am as x14_0_, costs6_.lst_upd_ts as x15_0_, commodit5_.com_dsc_tx as x16_0_, subcommo4_.scm_dsc_tx as x17_0_, fieldoff7_.fld_ofe_nam_tx as x18_0_, comments8_.cmt_tx as x19_0_, growingr9_.grw_rgn_id as x20_0_, itemrepo0_.avl_cd as x21_0_ from item_report itemrepo0_ left outer join report_region_link growingr1_ on itemrepo0_.itm_rpt_id=growingr1_.itm_rpt_id left outer join growing_region growingr2_ on growingr1_.grw_rgn_id=growingr2_.grw_rgn_id, item item3_, sub_commodity subcommo4_, commodity commodit5_, costs costs6_, field_office fieldoff7_, comments comments8_, report_region_link growingr9_ where itemrepo0_.itm_upc_cd=item3_.itm_upc_cd and item3_.scm_cd=subcommo4_.scm_cd and item3_.com_cd=subcommo4_.com_cd and item3_.dpt_cd=subcommo4_.dpt_cd and itemrepo0_.itm_upc_cd=item3_.itm_upc_cd and item3_.scm_cd=subcommo4_.scm_cd and item3_.com_cd=subcommo4_.com_cd and item3_.dpt_cd=subcommo4_.dpt_cd and subcommo4_.com_cd=commodit5_.com_cd and subcommo4_.dpt_cd=commodit5_.dpt_cd and itemrepo0_.itm_upc_cd=item3_.itm_upc_cd and itemrepo0_.itm_rpt_id=costs6_.cst_id and itemrepo0_.fld_ofe_id=fieldoff7_.fld_ofe_id and itemrepo0_.itm_rpt_id=comments8_.cmt_id and itemrepo0_.itm_rpt_id=growingr9_.itm_rpt_id and ((1=1 )) order by subcommo4_.scm_dsc_tx , commodit5_.com_dsc_tx , item3_.itm_upc_cd , itemrepo0_.itm_rpt_id
Notice the ',report_region_link growingr9_' that is added right before the where clause. This ends up not displaying ItemReports that don't have growing_regions associated with them. Is this necessary? Any thoughts on why this is being added back in?
The SQL would normally be: item_report left outer join report_region_link left outer join growing_region, item, sub_commodity, commodity, costs, field_office, comments
The same query (sans the ',report_region_link growingr9_') works:
select distinct itemrepo0_.itm_rpt_id as x0_0_, itemrepo0_.wek_too_pro_stt_dt as x1_0_, itemrepo0_.wek_too_pro_stt_dt as x2_0_, itemrepo0_.lst_upd_ts as x3_0_, itemrepo0_.crt_ts as x3_1_, itemrepo0_.upd_usr_id as x3_2_, itemrepo0_.crt_usr_id as x3_3_, itemrepo0_.ris_cd as x4_0_, item3_.itm_upc_cd as x5_0_, item3_.itm_nam_tx as x6_0_, item3_.top_020_cd as x7_0_, item3_.itm_siz_tx as x8_0_, item3_.itm_pak_qy as x9_0_, costs6_.ted_cd as x10_0_, costs6_.cur_low_cst_am as x11_0_, costs6_.cur_hgh_cst_am as x12_0_, costs6_.pjt_low_cst_am as x13_0_, costs6_.pjt_hgh_cst_am as x14_0_, costs6_.lst_upd_ts as x15_0_, commodit5_.com_dsc_tx as x16_0_, subcommo4_.scm_dsc_tx as x17_0_, fieldoff7_.fld_ofe_nam_tx as x18_0_, comments8_.cmt_tx as x19_0_, growingr1_.grw_rgn_id as x20_0_, itemrepo0_.avl_cd as x21_0_ from item_report itemrepo0_ left outer join report_region_link growingr1_ on itemrepo0_.itm_rpt_id=growingr1_.itm_rpt_id left outer join growing_region growingr2_ on growingr1_.grw_rgn_id=growingr2_.grw_rgn_id, item item3_, sub_commodity subcommo4_, commodity commodit5_, costs costs6_, field_office fieldoff7_, comments comments8_ where itemrepo0_.itm_upc_cd=item3_.itm_upc_cd and item3_.scm_cd=subcommo4_.scm_cd and item3_.com_cd=subcommo4_.com_cd and item3_.dpt_cd=subcommo4_.dpt_cd and itemrepo0_.itm_upc_cd=item3_.itm_upc_cd and item3_.scm_cd=subcommo4_.scm_cd and item3_.com_cd=subcommo4_.com_cd and item3_.dpt_cd=subcommo4_.dpt_cd and subcommo4_.com_cd=commodit5_.com_cd and subcommo4_.dpt_cd=commodit5_.dpt_cd and itemrepo0_.itm_upc_cd=item3_.itm_upc_cd and itemrepo0_.itm_rpt_id=costs6_.cst_id and itemrepo0_.fld_ofe_id=fieldoff7_.fld_ofe_id and itemrepo0_.itm_rpt_id=comments8_.cmt_id and ((1=1 )) order by subcommo4_.scm_dsc_tx , commodit5_.com_dsc_tx , item3_.itm_upc_cd , itemrepo0_.itm_rpt_id
Any thoughts on this? I'll look into createSqlQuery, but I'm puzzled why it's adding the GrowingRegion back on the end.
I can provide the config files if necessary.