On Fri, Sep 11, 2009 at 2:31 PM, Daryl Stultz <[email protected]> wrote:
> Let me put it another way. Let's say A to C is one to many. (A.cs is a > collection of C.) > > select a, c > from A as a > left join a.cs as c > where a.p1 = 2 and c.p1 = 3 > The above won't return A's that have no C's (or no C's with p1 = 3). I need > all A's with p1 = 2 regardless of the existence of related C's with p1 = 3. > > Do I need to do this in 2 passes? Get all my A's, then get my C's, adding A's and C's to my AdHocDataStructure? Is it common to run multiple queries to get collections of things in this way? Sometimes I want a list of A's and I want to know if each A has a particular child, C5. I would do this in SQL with a case statement in my select. select a.*, case when c.id is null then 0 else 1 end as hasSpecialChild from a left join c on c.aId = a.id and c.id = 5 where a.foo = bar Can I do this in JPA? How do you all solve these problems? Load in the A's and iterate over C's checking the ID? -- Daryl Stultz _____________________________________ 6 Degrees Software and Consulting, Inc. http://www.6degrees.com mailto:[email protected]
