Hello,
Note: I have read through the hibernate documentation, FAQ, tests, and also performed a few web searches.
Note #2: I'm using EntityMode.MAP
Let's say I have the following tables:
Order
Item
PromotionDetail
The PromotionDetail has a foreign key back to Orders in order to allow all the promotions for an order to be loaded efficiently.
I set up the following assocation from Item to PromotionDetail
Code:
<set name="promotions"
<key column="item_id"/>
<one-to-many entity-name="Promotion"/>
</set>
I retrieve one order using this query:
"from Order where order_id = ?"
I get the order and when I call serialize it using .toString(). Later I'm going to stream this via http but for now just debugging.
The query that I get is not optimal. There must be a way of fixing but not sure how to do it.
If I select fetch="join" or fetch="select", then I get one select per item which is not what I want.
If I select fetch="subselect" then I essentially get this query:
Code:
select * from PromotionDetail where promo_detail_id in (select promo_detail_id from Items where order_id = ?)
What I want is this query
Code:
select * from PromotionDetail where order_id = ?
How can I get this query without having to hard-code. I want the lazy-load to do the right thing. Is it possible to configure it such that it happens?
Any help would be appreciated.