users@glassfish.java.net

Re: Question on JPA _at_SqlResultSetMapping when using a native query

From: <glassfish_at_javadesktop.org>
Date: Tue, 24 Jun 2008 11:35:45 PDT

I found this thread while trying to figure out how to get data back from a native query.

I need to generate a bunch of different monotonically increasing ids. These are not primary keys, and I need access to an id value before it gets assigned to an entity. In regular SQL I would use an update/select on an id generation table, so I'm trying to do the same thing in JPA.

Given a native sql query like "select id from tab where type = 'x'", how do I go about getting the id value (an integer) back from the query? None of the examples in the spec or other sources seem to give an example of this. When I try
     Integer id = (Integer) query.getSingleResult()
I get a ClassCastException that indicates I am trying to mis-cast a Vector.

A pointer to some example code would be greatly appreciated. Thanks.
[Message sent by forum member 'dparker61' (dparker61)]

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