geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacek Laskowski" <ja...@laskowski.net.pl>
Subject Re: Force to load subobjects in OpenJPA
Date Tue, 27 Nov 2007 14:55:39 GMT
On Nov 27, 2007 3:45 PM, Tomasz Mazan <wind22@wp.pl> wrote:

> 1) if I use query like
>
> @NamedQueries({
>         @NamedQuery(name = "ProductWithDeps",
>                     query = "SELECT p FROM Product p"
>                                 + " WHERE p.number = :number")
> })
> product is found and returned, but if I use query like:
>
> 2)
> @NamedQueries({
>         @NamedQuery(name = "ProductWithDeps",
>                     query = "SELECT p FROM Product p"
>                             + " join fetch p.blocks"
>                                 + " WHERE p.number= :number")
> })
> I get null as a finder result. What's wrong ?

Most likely the entity doesn't have any blocks and thus the query
returns null (p.blocks evaluates to null, and the query returns only
entities that have at least one block in them - it's how INNER join
works). Add LEFT before JOIN FETCH and it should work as expected.

@NamedQueries({
       @NamedQuery(name = "ProductWithDeps",
                   query = "SELECT p FROM Product p"
                           + " LEFT JOIN FETCH p.blocks"
                               + " WHERE p.number= :number")
})

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl

Mime
View raw message