users@glassfish.java.net

JPA query: null values in the query result

From: <glassfish_at_javadesktop.org>
Date: Fri, 11 May 2007 03:50:08 PDT

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
[Message sent by forum member 'ale78' (ale78)]

http://forums.java.net/jive/thread.jspa?messageID=216470