-->
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: Loading Child Collections Problem
PostPosted: Wed Sep 09, 2009 4:58 am 
Newbie

Joined: Wed Sep 09, 2009 4:50 am
Posts: 2
Hi everyone,

I have a class "Product" which contains a collection of "Order". I'm looking for suggestions on how I can load every "Product", each with only the latest 10 "Order".

In SQL, querying the data would look something like this :
SELECT * FROM Product AS A LEFT OUTER JOIN (SELECT TOP 10 FROM Order ORDER BY CreateTime DESC) AS B ON A.ProductId = B.ProductId

I've been scratching my head for a day, and I can't get any way to do it properly (ICriteria, IQuery, ISQLQuery) using nHibernate. I'd greatly appreciate any suggestions people can offer.

Thanks a bunch,
--Gene


Top
 Profile  
 
 Post subject: Re: Loading Child Collections Problem
PostPosted: Wed Sep 09, 2009 3:09 pm 
Newbie

Joined: Wed Sep 09, 2009 4:50 am
Posts: 2
To solve this, I use a custom sql-query and loader.

<class name="Auction" lazy="false">
<id name="Id">
<generator class="guid" />
</id>

<bag name="Bids" lazy="false">
<key column="AuctionId"/>
<one-to-many class="VirtualBid.Domain.Bid,VirtualBid"/>
<loader query-ref="GetTopBids"/>
</bag>
</class>

<sql-query name="GetTopBids">
<load-collection alias="bid" role="VirtualBid.Domain.Auction.Bids"/>
<return alias="bid" class="VirtualBid.Domain.Bid, VirtualBid"/>
SELECT TOP 10 {bid.*} FROM Bid {bid} WHERE bid.AuctionId=? ORDER BY CreateTime DESC
</sql-query>


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.