-->
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.  [ 1 post ] 
Author Message
 Post subject: Map a collection with a subset of the matched rows
PostPosted: Mon Apr 03, 2006 3:02 pm 
Newbie

Joined: Mon Apr 03, 2006 2:50 pm
Posts: 1
I have a data model (simplified) that has customer to site (one to many). The sites have a start-date and stop-date field, and in the collection of sites retrieved from customer, I'd like to limit the sites to those that are "current", or current to an arbitrary date, like:

Code:
select customer.customer_id, site.site_id from customer, site
where site.customer_id = customer.customer_id
and site.start_date <= ?
and site.stop_date > ?


or ? could be "sysdate" (for Oracle, at least).

I already have my collection mapping set up so that I get all the sites for a customer (I know, congratulations...), but I'm trying to figure out the best way to limit the collection.

I can think of several ways: one, make a view in the database, which would make it impossible to use an arbitrary date, two, do it in code, or three, figure out how to do it with a mapping or a query. It appears that using a <subquery> on <class> might do what I want, but I'm not sure.

Is there any way to do this at runtime with an HQL query? Or is this a mapping-time thing?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.