-->
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: Need to perform lazy load using grand-parent key
PostPosted: Fri Nov 09, 2007 3:16 am 
Newbie

Joined: Fri Nov 09, 2007 3:04 am
Posts: 2
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.


Top
 Profile  
 
 Post subject: Any ideas?
PostPosted: Fri Nov 09, 2007 7:38 pm 
Newbie

Joined: Fri Nov 09, 2007 3:04 am
Posts: 2
Any ideas?


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