users@glassfish.java.net

null entity from left join using sqlResultSetMapping - is it possible

From: <glassfish_at_javadesktop.org>
Date: Sun, 09 Mar 2008 10:43:34 PST

Hi, i have an namedNativeQuery which consists of a left join across 2 managed entities using a resultSetMapping. All is fine, except that the query by design sometimes doesn't match on the second entity and returns null. Is it possible to handle this using JPA?

The problem i have is that if i use a resultSetMapping, i get an error that the primary key of the second entity is null, as all fields from the query for the second entity are null.

Is it possible to have JPA create an empty/null entity object in this instance?

I can force the primary key of the entity to have a value (if it is null, i create the entity so i know what value to use, it isn't just random) but i'm worried this will pollute the cache and not be persisted correctly when i come to create the object as the entity doesn't actually exist in the db.

Any suggestions

Thanks
[Message sent by forum member 'jsl123' (jsl123)]

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