persistence@glassfish.java.net

JPA query: null values in the query result

From: ales <ales_at_mincol.com>
Date: Fri, 11 May 2007 13:35:13 +0200

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)