-->
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: Newbie HQL question regarding collections
PostPosted: Tue Dec 14, 2004 5:22 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
I'm sure there has to be an easy way to do this, but, I'm just not seeing it right now.

I'm trying to do something like the following, but, it's not working.

SELECT c FROM mypackage.Course c WHERE c.sections.term.startTime > '2004-12-01'

The way my model is setup, a course has many sections, and a section has a single term which has a Date property named startTime.

I want to do a query that returns all courses that have a section that is in a term that has a start time greater than a given date.

The problem is that I don't know what the syntax is for dealing with "sections" which is a collection. I tried doing an INNER JOIN which worked. However, that's not really what I'm looking for as it gives me duplicate course objects.

I also looked at using ELEMENTS(), but, in that case I would need to do something like ELEMENTS(c.sections).term.startTime which doesn't work.

Can anyone help?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 6:45 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
It looks like I can do what I want using something like the following using the DISTINCT keyword.

SELECT DISTINCT c FROM Course c INNER JOIN c.sections s WHERE s.term.startTime > '2004-12-01'

I was assuming that HQL had something like the following which you can do in EJBQL. i.e. an IN()

SELECT OBJECT(c) FROM Course c, IN(c.sections) s WHERE s.term.startTime > '2004-12-01'


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.