Hi Gordon,
If you intend to navigate through an association, I'd agree that you
need to use an outer join. But this case is just trying to retrieve
the associated entity, and this case is pretty well described in the
section 4.8.3:
If the result of a query corresponds to aassociation-field or state-
field whose value is null, that null
value is returned in the result of the query method. The IS NOT NULL
construct can be used to eliminate such null values from the result
set of the query.
If NULL values are excluded anyway, there's no reason for this
discussion.
I'd call it a bug.
Craig
On May 11, 2007, at 11:13 AM, Gordon Yorke wrote:
> Try this query:
> SELECT assocEnt, e.description FROM Entity e LEFT OUTER JOIN
> e.associatedEntity assocEnt WHERE e.description LIKE 'foo'
>
> Because there may be no associated entity you must perform an OUTER
> JOIN.
> --Gordon
>
> -----Original Message-----
> From: ales [mailto:ales_at_mincol.com]
> Sent: Friday, May 11, 2007 7:35 AM
> To: persistence_at_glassfish.dev.java.net
> Subject: JPA query: null values in the query result
>
>
> Hi all,
> please help me if possible. I have the following situation:
>
> - Entity
> - AssociatedEntity
> - Entity has field associatedEntity
> - database table contains many Entity records WITHOUT references to
> AssociatedEntities
> - when I use the following JPA query: SELECT e.associatedEntity.name,
> e.description FROM Entity e WHERE e.description LIKE 'foo' nothing is
> returned (there are Entity descriptions with value foo)
> - when I use the following JPA query: SELECT e.associatedEntity,
> e.description FROM Entity e WHERE e.description LIKE 'foo' nothing is
> returned (there are Entity descriptions with value foo)
> - when I change Entity records to have references to
> AssociatedEntities
> mentioned queries return data
>
> I do not understand why mentioned queries when Entity records do not
> have references to AssociatedEntities do not return any data. "JSR
> 220:
> Enterprise JavaBeansTM,Version 3.0" in "4.8.3 Null Values in the Query
> Result" says:
>
> If the result of a query corresponds to a association-field or
> state-field whose value is null, that null
> value is returned in the result of the query method.
>
> IMHO expression "e.associatedEntity" ends with association-field so
> null
> value should be returned in the result. It seems for me that behaviour
> of the Hibernate framework is the same.
>
> Best regards,
>
> Ales
>
>
> Implementation-Title: TopLink Essentials
> Implementation-Version: 2.0-b43-beta3 (04/18/2007)
Craig Russell
Architect, Sun Java Enterprise System
http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell_at_sun.com
P.S. A good JDO? O, Gasp!
- application/pkcs7-signature attachment: smime.p7s