On Nov 27, 2007 3:45 PM, Tomasz Mazan <[EMAIL PROTECTED]> 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