users@glassfish.java.net

Problem with Native Query

From: <glassfish_at_javadesktop.org>
Date: Tue, 29 Jul 2008 21:58:51 PDT

I have a native query:

[code]
select distinct tx.* from tablex tx, tabley ty where ty.xid = tx.id and ty.prop1 = 1
 order by tx.prop2
[/code]

Then, in my code:

[code]
List retValue = em.createNativeQuery(sql, TableX.class).getResultList();
[/code]

The problem is that this works, but the result set is incomplete. Specifically SOME, but not ALL of the fields of TableX are populated.

This then frustrates later queries that happen to link to TableX, because the cache is polluted. I get all of the rows, but the data is wrong.

However, if I do EQL:
[code]
List retValue = em.createQuery("select tx from TableX tx").getResultList();
[/code]

THIS works just fine.

(As with all posts to the forum, I think I finally figured this out.)

I believe that the problem is that in my class, this is wrong:
[code]
@Column(name = "someLongName")
private String someLongName;
[/code]

When in fact, the actual column name is "somelongname", note the case discrepancy.

What's bothersome, is that the EQL works (so somehow the JPA is smart enough to downshift the names), while the SQL does not.

This may well be a feature and not a "bug", but I figured I'd post it anyway.
[Message sent by forum member 'whartung' (whartung)]

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