I'm having trouble understanding why I cannot get Hibernate to do a somewhat complex JOIN in a single query. I hunted down all of the EAGER initialized attribtues and either JOIN FETCHED them in the HQL or made them LAZY.
What Hibernate seems to do, is run the query first getting the IDs and Columns, then again just getting the columns. It seems like the first query has all of the information the second query has so it doesn't make much sense.
Here is my HQL:
FROM OrderItem oi
JOIN FETCH oi.order o
JOIN FETCH o.market m
JOIN FETCH o.customer c
JOIN FETCH oi.orderItemStatus s
JOIN FETCH oi.product p
LEFT JOIN FETCH p.urlMapping url
LEFT JOIN FETCH url.market urlMarket
WHERE oi.id = :itemId
The First Query:
select
orderitem0_.item_new_id as item1_46_0_,
order1_.order_id as order1_44_1_,
market2_.market_id as market1_35_2_,
customer3_.customer_id as customer1_17_3_,
orderitems4_.status_id as status1_49_4_,
product5_.product_id as product1_55_5_,
urlmapping6_.id as id81_6_,
market7_.market_id as market1_35_7_,
orderitem0_.item_affiliate_number as item2_46_0_,
orderitem0_.item_amount_off as item3_46_0_,
orderitem0_.item_cancel as item4_46_0_,
orderitem0_.item_cancel_date as item5_46_0_,
orderitem0_.item_completed as item6_46_0_,
orderitem0_.item_completed_date as item7_46_0_,
orderitem0_.item_create_proof as item8_46_0_,
orderitem0_.item_created_on as item9_46_0_,
orderitem0_.item_dol_doc_id as item10_46_0_,
orderitem0_.item_dol_session_id as item11_46_0_,
orderitem0_.item_designer_id as item45_46_0_,
orderitem0_.item_discount_order_amount as item12_46_0_,
orderitem0_.item_discount_total as item13_46_0_,
orderitem0_.item_unitprice_group as item14_46_0_,
orderitem0_.item_is_reorder as item15_46_0_,
orderitem0_.item_is_sample as item16_46_0_,
orderitem0_.item_stock as item17_46_0_,
orderitem0_.item_number as item18_46_0_,
orderitem0_.item_quantity_rerun as item19_46_0_,
orderitem0_.item_market_id as item46_46_0_,
orderitem0_.item_needby as item20_46_0_,
orderitem0_.item_mark_as_noncomposite as item21_46_0_,
orderitem0_.item_note as item22_46_0_,
orderitem0_.item_reason_hold as item23_46_0_,
orderitem0_.order_id as order47_46_0_,
orderitem0_.status_id as status48_46_0_,
orderitem0_.item_unitprice_original as item24_46_0_,
orderitem0_.item_parent_id as item25_46_0_,
orderitem0_.pathway_id as pathway26_46_0_,
orderitem0_.item_pause_at_status_id as item49_46_0_,
orderitem0_.item_pause_at_reason as item27_46_0_,
orderitem0_.item_percent_off as item28_46_0_,
orderitem0_.product_id as product50_46_0_,
orderitem0_.item_proof_creation_date as item29_46_0_,
orderitem0_.item_quantity as item30_46_0_,
orderitem0_.item_rerun_type_list as item31_46_0_,
orderitem0_.item_reviewed as item32_46_0_,
orderitem0_.item_saly as item33_46_0_,
orderitem0_.item_saly_type as item34_46_0_,
orderitem0_.item_saly_order as item35_46_0_,
orderitem0_.item_sequence as item36_46_0_,
orderitem0_.item_ship_date as item37_46_0_,
orderitem0_.item_ship_with as item38_46_0_,
orderitem0_.substrate_id as substrate51_46_0_,
orderitem0_.item_total as item39_46_0_,
orderitem0_.item_tracking_number as item40_46_0_,
orderitem0_.item_unitprice as item41_46_0_,
orderitem0_.item_upsell as item42_46_0_,
orderitem0_.item_user_approval_initials as item43_46_0_,
orderitem0_.item_wrapper as item44_46_0_,
order1_.order_paid_amount as order2_44_1_,
order1_.order_bill_address1 as order3_44_1_,
order1_.order_bill_address2 as order4_44_1_,
order1_.order_bill_city as order5_44_1_,
order1_.order_bill_company as order6_44_1_,
order1_.order_bill_country as order7_44_1_,
order1_.order_bill_email as order8_44_1_,
order1_.order_bill_fax as order9_44_1_,
order1_.order_bill_first as order10_44_1_,
order1_.order_bill_last as order11_44_1_,
order1_.order_bill_phone as order12_44_1_,
order1_.order_bill_state as order76_44_1_,
order1_.order_bill_zip as order13_44_1_,
order1_.order_committed as order14_44_1_,
order1_.order_completed as order15_44_1_,
order1_.order_completed_date as order16_44_1_,
order1_.order_email_conf_sent as order17_44_1_,
order1_.order_contact_address_id as order77_44_1_,
order1_.customer_id as customer78_44_1_,
order1_.order_crs_id as order79_44_1_,
order1_.order_designer_id as order80_44_1_,
order1_.order_discount_subtotal as order18_44_1_,
order1_.order_discount_total as order19_44_1_,
order1_.order_event_date_as_date as order20_44_1_,
order1_.order_event_date as order21_44_1_,
order1_.order_fx_rate as order22_44_1_,
order1_.order_discount_group as order23_44_1_,
order1_.order_discount_pricedrift as order24_44_1_,
order1_.order_internal as order25_44_1_,
order1_.order_invoice as order26_44_1_,
order1_.order_invoice_number as order27_44_1_,
order1_.order_ip_address as order28_44_1_,
order1_.order_host as order29_44_1_,
order1_.order_item_count as order30_44_1_,
order1_.order_latitude as order31_44_1_,
order1_.order_longitude as order32_44_1_,
order1_.market_id as market81_44_1_,
order1_.order_notes as order33_44_1_,
order1_.order_clone_id as order82_44_1_,
order1_.order_number as order34_44_1_,
order1_.order_total as order35_44_1_,
order1_.order_paid as order36_44_1_,
order1_.gateway_id as gateway83_44_1_,
order1_.order_date as order37_44_1_,
order1_.order_product_total as order38_44_1_,
order1_.order_product_discount as order39_44_1_,
order1_.order_proof_format as order40_44_1_,
order1_.order_proof_send_to as order41_44_1_,
order1_.order_po_number as order42_44_1_,
order1_.order_receive_marketing as order43_44_1_,
order1_.order_web_ref_id as order44_44_1_,
order1_.region_id as region84_44_1_,
order1_.order_roi_matched as order45_44_1_,
order1_.sector_id as sector85_44_1_,
order1_.order_service_total as order46_44_1_,
order1_.order_service_discount as order47_44_1_,
order1_.order_ship_blind as order48_44_1_,
order1_.order_ship_date as order49_44_1_,
order1_.order_ship_address1 as order50_44_1_,
order1_.order_ship_address2 as order51_44_1_,
order1_.order_ship_residential as order52_44_1_,
order1_.order_shipping_cost as order53_44_1_,
order1_.order_ship_city as order54_44_1_,
order1_.order_ship_company as order55_44_1_,
order1_.order_ship_country as order56_44_1_,
order1_.order_discount_shipping as order57_44_1_,
order1_.order_ship_first as order58_44_1_,
order1_.order_ship_last as order59_44_1_,
order1_.order_shipping_method as order60_44_1_,
order1_.order_ship_state as order86_44_1_,
order1_.order_shipping_total as order61_44_1_,
order1_.order_ship_zip as order62_44_1_,
order1_.order_source as order63_44_1_,
order1_.order_subindustry_code as order64_44_1_,
order1_.order_subtotal as order65_44_1_,
order1_.order_tax_exempt as order66_44_1_,
order1_.order_tax_exemptable as order67_44_1_,
order1_.order_tax_product as order68_44_1_,
order1_.order_tax_rate as order69_44_1_,
order1_.order_tax_service as order70_44_1_,
order1_.order_tax_shipping as order71_44_1_,
order1_.order_tax as order72_44_1_,
order1_.order_transfer as order73_44_1_,
order1_.order_transfer_date as order74_44_1_,
order1_.order_type_id as order75_44_1_,
market2_.market_allow_alt_payment as market2_35_2_,
market2_.market_auto_applied_discount_code as market30_35_2_,
market2_.market_brand_logo as market3_35_2_,
market2_.market_brand_password as market4_35_2_,
market2_.market_brand as market5_35_2_,
market2_.market_browse_banner_location as market6_35_2_,
market2_.market_cart_banner_hide_type_ids as market7_35_2_,
market2_.market_cart_banner_location as market8_35_2_,
market2_.market_cart_banner_show_type_ids as market9_35_2_,
market2_.market_cart_banner_title as market10_35_2_,
market2_.market_consumer as market11_35_2_,
market2_.market_phone as market12_35_2_,
market2_.market_default_cart_settings as market13_35_2_,
market2_.market_default_gateway_id as market31_35_2_,
market2_.market_description as market14_35_2_,
market2_.market_details_banner_location as market15_35_2_,
market2_.market_disable as market16_35_2_,
market2_.market_allow_dol as market17_35_2_,
market2_.market_force_dol as market18_35_2_,
market2_.market_allow_ground_shipping as market19_35_2_,
market2_.market_allow_group_discount as market20_35_2_,
market2_.market_homepage_url as market21_35_2_,
market2_.market_css as market22_35_2_,
market2_.market_footer as market23_35_2_,
market2_.market_header as market24_35_2_,
market2_.market_orderable as market25_35_2_,
market2_.market_allow_gateway_change as market26_35_2_,
market2_.market_base as market27_35_2_,
market2_.market_html as market28_35_2_,
market2_.sector_id as sector32_35_2_,
market2_.market_taxexempt as market29_35_2_,
customer3_.customer_company as customer2_17_3_,
customer3_.customer_default_market_id as customer13_17_3_,
customer3_.customer_default_subindustry_code as customer3_17_3_,
customer3_.customer_default_sector_id as customer14_17_3_,
customer3_.customer_default_ship_blind as customer4_17_3_,
customer3_.customer_disable as customer5_17_3_,
customer3_.customer_merge_check_date as customer6_17_3_,
customer3_.customer_merge_to as customer7_17_3_,
customer3_.customer_name as customer8_17_3_,
customer3_.customer_reseller_id as customer9_17_3_,
customer3_.customer_tax_id as customer10_17_3_,
customer3_.customer_title as customer11_17_3_,
customer3_.customer_web_created as customer12_17_3_,
orderitems4_.status_description as status2_49_4_,
orderitems4_.status_web_description as status3_49_4_,
product5_.product_active_date as product2_55_5_,
product5_.product_batch_code as product3_55_5_,
product5_.product_cart_banner_hide_type_ids as product4_55_5_,
product5_.product_cart_banner_location as product5_55_5_,
product5_.product_cart_banner_show_type_ids as product6_55_5_,
product5_.product_classification_id as product46_55_5_,
product5_.product_clone_id as product47_55_5_,
product5_.product_converted_to_imprints as product7_55_5_,
product5_.product_default_crs_id as product48_55_5_,
product5_.product_description as product8_55_5_,
product5_.product_designer_choice_date as product9_55_5_,
product5_.product_designer_name as product10_55_5_,
product5_.product_allow_designer_notes as product11_55_5_,
product5_.product_details_banner_location as product12_55_5_,
product5_.product_disable as product13_55_5_,
product5_.product_display_web as product14_55_5_,
product5_.product_family_image_location as product15_55_5_,
product5_.product_family_medium_location as product16_55_5_,
product5_.product_family_small_location as product17_55_5_,
product5_.product_family_thumbnail_location as product18_55_5_,
product5_.product_family_xs_location as product19_55_5_,
product5_.product_family_xl_location as product20_55_5_,
product5_.product_image_location as product21_55_5_,
product5_.product_imprint_description as product22_55_5_,
product5_.product_imprintable as product23_55_5_,
product5_.product_indesign_template as product24_55_5_,
product5_.product_medium_location as product25_55_5_,
product5_.product_netsuite_id as product26_55_5_,
product5_.product_netsuite_update as product27_55_5_,
product5_.product_outofstock as product28_55_5_,
product5_.product_outofstock_description as product29_55_5_,
product5_.product_processor_code as product30_55_5_,
product5_.product_discount_code as product31_55_5_,
product5_.product_rank as product32_55_5_,
product5_.product_seo_title as product33_55_5_,
product5_.product_shipping_notes as product34_55_5_,
product5_.product_small_location as product35_55_5_,
product5_.product_status_id as product49_55_5_,
product5_.product_stylecode as product36_55_5_,
product5_.template_id as template50_55_5_,
product5_.product_template_location as product37_55_5_,
product5_.product_template_metadata as product38_55_5_,
product5_.product_thumbnail_location as product39_55_5_,
product5_.product_xs_location as product40_55_5_,
product5_.type_id as type51_55_5_,
product5_.product_shakespeare as product41_55_5_,
product5_.product_vipp as product42_55_5_,
product5_.product_web_description as product43_55_5_,
product5_.product_xl_location as product44_55_5_,
product5_.product_xml_location as product45_55_5_,
urlmapping6_.market_id as market4_81_6_,
urlmapping6_.product_id as product5_81_6_,
urlmapping6_.static_filename as static2_81_6_,
urlmapping6_.url as url81_6_,
market7_.market_allow_alt_payment as market2_35_7_,
market7_.market_auto_applied_discount_code as market30_35_7_,
market7_.market_brand_logo as market3_35_7_,
market7_.market_brand_password as market4_35_7_,
market7_.market_brand as market5_35_7_,
market7_.market_browse_banner_location as market6_35_7_,
market7_.market_cart_banner_hide_type_ids as market7_35_7_,
market7_.market_cart_banner_location as market8_35_7_,
market7_.market_cart_banner_show_type_ids as market9_35_7_,
market7_.market_cart_banner_title as market10_35_7_,
market7_.market_consumer as market11_35_7_,
market7_.market_phone as market12_35_7_,
market7_.market_default_cart_settings as market13_35_7_,
market7_.market_default_gateway_id as market31_35_7_,
market7_.market_description as market14_35_7_,
market7_.market_details_banner_location as market15_35_7_,
market7_.market_disable as market16_35_7_,
market7_.market_allow_dol as market17_35_7_,
market7_.market_force_dol as market18_35_7_,
market7_.market_allow_ground_shipping as market19_35_7_,
market7_.market_allow_group_discount as market20_35_7_,
market7_.market_homepage_url as market21_35_7_,
market7_.market_css as market22_35_7_,
market7_.market_footer as market23_35_7_,
market7_.market_header as market24_35_7_,
market7_.market_orderable as market25_35_7_,
market7_.market_allow_gateway_change as market26_35_7_,
market7_.market_base as market27_35_7_,
market7_.market_html as market28_35_7_,
market7_.sector_id as sector32_35_7_,
market7_.market_taxexempt as market29_35_7_
from
order_item orderitem0_
inner join
order_master order1_
on orderitem0_.order_id=order1_.order_id
inner join
market market2_
on order1_.market_id=market2_.market_id
inner join
customer_list customer3_
on order1_.customer_id=customer3_.customer_id
inner join
order_status orderitems4_
on orderitem0_.status_id=orderitems4_.status_id
inner join
product product5_
on orderitem0_.product_id=product5_.product_id
left outer join
url_mapping urlmapping6_
on product5_.product_id=urlmapping6_.product_id
left outer join
market market7_
on urlmapping6_.market_id=market7_.market_id
where
orderitem0_.item_new_id=?
Then it runs the following immeidately after during the query.uniqueResult():
select
orderitems0_.order_id as order47_44_6_,
orderitems0_.item_new_id as item1_6_,
orderitems0_.item_new_id as item1_46_5_,
orderitems0_.item_affiliate_number as item2_46_5_,
orderitems0_.item_amount_off as item3_46_5_,
orderitems0_.item_cancel as item4_46_5_,
orderitems0_.item_cancel_date as item5_46_5_,
orderitems0_.item_completed as item6_46_5_,
orderitems0_.item_completed_date as item7_46_5_,
orderitems0_.item_create_proof as item8_46_5_,
orderitems0_.item_created_on as item9_46_5_,
orderitems0_.item_dol_doc_id as item10_46_5_,
orderitems0_.item_dol_session_id as item11_46_5_,
orderitems0_.item_designer_id as item45_46_5_,
orderitems0_.item_discount_order_amount as item12_46_5_,
orderitems0_.item_discount_total as item13_46_5_,
orderitems0_.item_unitprice_group as item14_46_5_,
orderitems0_.item_is_reorder as item15_46_5_,
orderitems0_.item_is_sample as item16_46_5_,开发者_如何学运维
orderitems0_.item_stock as item17_46_5_,
orderitems0_.item_number as item18_46_5_,
orderitems0_.item_quantity_rerun as item19_46_5_,
orderitems0_.item_market_id as item46_46_5_,
orderitems0_.item_needby as item20_46_5_,
orderitems0_.item_mark_as_noncomposite as item21_46_5_,
orderitems0_.item_note as item22_46_5_,
orderitems0_.item_reason_hold as item23_46_5_,
orderitems0_.order_id as order47_46_5_,
orderitems0_.status_id as status48_46_5_,
orderitems0_.item_unitprice_original as item24_46_5_,
orderitems0_.item_parent_id as item25_46_5_,
orderitems0_.pathway_id as pathway26_46_5_,
orderitems0_.item_pause_at_status_id as item49_46_5_,
orderitems0_.item_pause_at_reason as item27_46_5_,
orderitems0_.item_percent_off as item28_46_5_,
orderitems0_.product_id as product50_46_5_,
orderitems0_.item_proof_creation_date as item29_46_5_,
orderitems0_.item_quantity as item30_46_5_,
orderitems0_.item_rerun_type_list as item31_46_5_,
orderitems0_.item_reviewed as item32_46_5_,
orderitems0_.item_saly as item33_46_5_,
orderitems0_.item_saly_type as item34_46_5_,
orderitems0_.item_saly_order as item35_46_5_,
orderitems0_.item_sequence as item36_46_5_,
orderitems0_.item_ship_date as item37_46_5_,
orderitems0_.item_ship_with as item38_46_5_,
orderitems0_.substrate_id as substrate51_46_5_,
orderitems0_.item_total as item39_46_5_,
orderitems0_.item_tracking_number as item40_46_5_,
orderitems0_.item_unitprice as item41_46_5_,
orderitems0_.item_upsell as item42_46_5_,
orderitems0_.item_user_approval_initials as item43_46_5_,
orderitems0_.item_wrapper as item44_46_5_,
market1_.market_id as market1_35_0_,
market1_.market_allow_alt_payment as market2_35_0_,
market1_.market_auto_applied_discount_code as market30_35_0_,
market1_.market_brand_logo as market3_35_0_,
market1_.market_brand_password as market4_35_0_,
market1_.market_brand as market5_35_0_,
market1_.market_browse_banner_location as market6_35_0_,
market1_.market_cart_banner_hide_type_ids as market7_35_0_,
market1_.market_cart_banner_location as market8_35_0_,
market1_.market_cart_banner_show_type_ids as market9_35_0_,
market1_.market_cart_banner_title as market10_35_0_,
market1_.market_consumer as market11_35_0_,
market1_.market_phone as market12_35_0_,
market1_.market_default_cart_settings as market13_35_0_,
market1_.market_default_gateway_id as market31_35_0_,
market1_.market_description as market14_35_0_,
market1_.market_details_banner_location as market15_35_0_,
market1_.market_disable as market16_35_0_,
market1_.market_allow_dol as market17_35_0_,
market1_.market_force_dol as market18_35_0_,
market1_.market_allow_ground_shipping as market19_35_0_,
market1_.market_allow_group_discount as market20_35_0_,
market1_.market_homepage_url as market21_35_0_,
market1_.market_css as market22_35_0_,
market1_.market_footer as market23_35_0_,
market1_.market_header as market24_35_0_,
market1_.market_orderable as market25_35_0_,
market1_.market_allow_gateway_change as market26_35_0_,
market1_.market_base as market27_35_0_,
market1_.market_html as market28_35_0_,
market1_.sector_id as sector32_35_0_,
market1_.market_taxexempt as market29_35_0_,
orderitems2_.status_id as status1_49_1_,
orderitems2_.status_description as status2_49_1_,
orderitems2_.status_web_description as status3_49_1_,
product3_.product_id as product1_55_2_,
product3_.product_active_date as product2_55_2_,
product3_.product_batch_code as product3_55_2_,
product3_.product_cart_banner_hide_type_ids as product4_55_2_,
product3_.product_cart_banner_location as product5_55_2_,
product3_.product_cart_banner_show_type_ids as product6_55_2_,
product3_.product_classification_id as product46_55_2_,
product3_.product_clone_id as product47_55_2_,
product3_.product_converted_to_imprints as product7_55_2_,
product3_.product_default_crs_id as product48_55_2_,
product3_.product_description as product8_55_2_,
product3_.product_designer_choice_date as product9_55_2_,
product3_.product_designer_name as product10_55_2_,
product3_.product_allow_designer_notes as product11_55_2_,
product3_.product_details_banner_location as product12_55_2_,
product3_.product_disable as product13_55_2_,
product3_.product_display_web as product14_55_2_,
product3_.product_family_image_location as product15_55_2_,
product3_.product_family_medium_location as product16_55_2_,
product3_.product_family_small_location as product17_55_2_,
product3_.product_family_thumbnail_location as product18_55_2_,
product3_.product_family_xs_location as product19_55_2_,
product3_.product_family_xl_location as product20_55_2_,
product3_.product_image_location as product21_55_2_,
product3_.product_imprint_description as product22_55_2_,
product3_.product_imprintable as product23_55_2_,
product3_.product_indesign_template as product24_55_2_,
product3_.product_medium_location as product25_55_2_,
product3_.product_netsuite_id as product26_55_2_,
product3_.product_netsuite_update as product27_55_2_,
product3_.product_outofstock as product28_55_2_,
product3_.product_outofstock_description as product29_55_2_,
product3_.product_processor_code as product30_55_2_,
product3_.product_discount_code as product31_55_2_,
product3_.product_rank as product32_55_2_,
product3_.product_seo_title as product33_55_2_,
product3_.product_shipping_notes as product34_55_2_,
product3_.product_small_location as product35_55_2_,
product3_.product_status_id as product49_55_2_,
product3_.product_stylecode as product36_55_2_,
product3_.template_id as template50_55_2_,
product3_.product_template_location as product37_55_2_,
product3_.product_template_metadata as product38_55_2_,
product3_.product_thumbnail_location as product39_55_2_,
product3_.product_xs_location as product40_55_2_,
product3_.type_id as type51_55_2_,
product3_.product_shakespeare as product41_55_2_,
product3_.product_vipp as product42_55_2_,
product3_.product_web_description as product43_55_2_,
product3_.product_xl_location as product44_55_2_,
product3_.product_xml_location as product45_55_2_,
urlmapping4_.id as id81_3_,
urlmapping4_.market_id as market4_81_3_,
urlmapping4_.product_id as product5_81_3_,
urlmapping4_.static_filename as static2_81_3_,
urlmapping4_.url as url81_3_,
market5_.market_id as market1_35_4_,
market5_.market_allow_alt_payment as market2_35_4_,
market5_.market_auto_applied_discount_code as market30_35_4_,
market5_.market_brand_logo as market3_35_4_,
market5_.market_brand_password as market4_35_4_,
market5_.market_brand as market5_35_4_,
market5_.market_browse_banner_location as market6_35_4_,
market5_.market_cart_banner_hide_type_ids as market7_35_4_,
market5_.market_cart_banner_location as market8_35_4_,
market5_.market_cart_banner_show_type_ids as market9_35_4_,
market5_.market_cart_banner_title as market10_35_4_,
market5_.market_consumer as market11_35_4_,
market5_.market_phone as market12_35_4_,
market5_.market_default_cart_settings as market13_35_4_,
market5_.market_default_gateway_id as market31_35_4_,
market5_.market_description as market14_35_4_,
market5_.market_details_banner_location as market15_35_4_,
market5_.market_disable as market16_35_4_,
market5_.market_allow_dol as market17_35_4_,
market5_.market_force_dol as market18_35_4_,
market5_.market_allow_ground_shipping as market19_35_4_,
market5_.market_allow_group_discount as market20_35_4_,
market5_.market_homepage_url as market21_35_4_,
market5_.market_css as market22_35_4_,
market5_.market_footer as market23_35_4_,
market5_.market_header as market24_35_4_,
market5_.market_orderable as market25_35_4_,
market5_.market_allow_gateway_change as market26_35_4_,
market5_.market_base as market27_35_4_,
market5_.market_html as market28_35_4_,
market5_.sector_id as sector32_35_4_,
market5_.market_taxexempt as market29_35_4_
from
order_item orderitems0_
left outer join
market market1_
on orderitems0_.item_market_id=market1_.market_id
left outer join
order_status orderitems2_
on orderitems0_.status_id=orderitems2_.status_id
left outer join
product product3_
on orderitems0_.product_id=product3_.product_id
left outer join
url_mapping urlmapping4_
on product3_.product_id=urlmapping4_.product_id
left outer join
market market5_
on urlmapping4_.market_id=market5_.market_id
where
orderitems0_.order_id=?
How can I adjust this query to make it perform a single call?
This was a simple issue, i had missed a circular dependecy between Order and OrderItem. Order was eagerly loading OrderItems so when I retrieve and order off of OrderItem it thinks it needs to get the items twice, once for the lookup and once for the eager join on the order.
This actually makes sense because I'll only have the item that I queried the order with in the original query and the second query was getting the remaining items.
So there are two solutions:
- Don't care about the other items and make Order.orderItems lazy
- Add a JOIN FETCH statement specifically for the Order's orderItems collection
The first has implications throughout the application as it is often expected the items be there. The second grows the query when I only actually need the singular item and not everything on the order.
I'm becoming to think the EAGER loading option should not be available and developers should have to write HQL or Criteria to get joined objects to avoid the downfalls of the first option, but hey I also like writing strait SQL :P.
If you want to have more control of the queries, use iBatis.
精彩评论