I could some help building a JPA query that isn't quite as trivial as
the ones I've had to build before.

I have a "Product" entity, with some subclasses, including "Device".
The "Product" entity has a "childFoos" one-to-many list, whose element
type is "Foo".

I need to get a list of all the unique "Foo" objects in the "childFoos"
list for all "Device" objects.

One guess might be "select dev.childFoos from Device dev".  This fails
with "Query projections cannot include array, collection, or map
fields.".

After looking at more examples in the OpenJPA doc, I tried "select foo
from Device dev, in(dev.childFoos) foo".  This didn't fail, but it
didn't give me anything, either.  At this point, I assumed I needed a
"fetch join" in here somewhere.  As a result, I tried "select foo from
Device dev left join fetch dev.childFoos, in(dev.childFoos) foo".

This appeared to work.  Is that the best way to do this?  Do I need to
add "distinct" to this if there could be duplicates in the union?

As this returns a relatively large list, I took the advice in the "Large
Result Set Proxies" section and iterated through the list, calling
"OpenJPAPersistence.close(iter)" in the finally block.

Reply via email to