openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "KARR, DAVID (ATTCINW)" <dk0...@att.com>
Subject RE: JPQL to get association members, but only ones that fulfill a condition
Date Wed, 03 Feb 2010 20:23:23 GMT
> -----Original Message-----
> From: Daryl Stultz [mailto:daryl@6degrees.com]
> Sent: Wednesday, February 03, 2010 12:00 PM
> To: users@openjpa.apache.org
> Subject: Re: JPQL to get association members, but only ones that
> fulfill a condition
> 
> On Wed, Feb 3, 2010 at 2:12 PM, KARR, DAVID (ATTCINW)
> <dk068x@att.com>wrote:
> 
> > So I changed my query to:
> >
> > select foo from packagepath.Foo foo left join fetch foo.childBars as
> bar
> >   where foo.id=:id and current_date between bar.startDate and
> > bar.endDate
> >
> > try this:
> 
> select distinct foo from packagepath.Foo foo
> left join foo.childBars as bar
> left join fetch foo.childBars
> where foo.id=:id
> and current_date between bar.startDate and bar.endDate
> 
> Notice "distinct". You might find it works without out it bug a bug
> will
> bite you later...
> 
> I'm not sure if you are expecting to get a subset of foo.childBars. If
> you
> are, this won't work.

I don't understand the last statement here.

When I tried this strategy, it resulted in no rows returned, and I know
that there's at least one "bar" with a current date range, but I know
there are several that do not.  I tried both with and without
"distinct", with the same result.

I have a feeling I'm heading towards having to construct a specific
query for the bars that are child of this foo and are in the date range.

Mime
View raw message