File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes JPA Native Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA Native Query" Watch "JPA Native Query" New topic
Author

JPA Native Query

Anand Parthasarathy
Greenhorn

Joined: May 23, 2011
Posts: 13
Hi,

I am trying to execute a native query and pass run-time parameters and get the result as a List. When I try to process the Object [], one of the columns fetched is a String. But it comes out as java.lang.Character instead of String. Here is the query below:



The EXP_STATUS column could not be typecasted into String as it is of type Character. Any ideas of why it does not work? Even String.valueOf(obj [0]) results only in the 1st character 'E' of the String.

Regards,
-Anand
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Odd, what JPA provider and JDBC driver are you using?

How are you executing the native query, are you mapping the result at all?

Try executing the query through raw JDBC to see what the JDBC driver is returning.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Anand Parthasarathy
Greenhorn

Joined: May 23, 2011
Posts: 13
Hi James,

We use the Entity manager from EJB 3.0. We use Oracle application server and oracle database. I am not mapping my result. I just obtain it as a List<Object []> where the Object [] will contain each row information.

I have this problem only with the quoted string as mentioned in the query. I do not have a problem when the String is obtained from the data stored in the database.

FYI - I did try with the raw JDBC and it worked out fine.

Regards,
-Anand

James Sutherland wrote:Odd, what JPA provider and JDBC driver are you using?

How are you executing the native query, are you mapping the result at all?

Try executing the query through raw JDBC to see what the JDBC driver is returning.
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
I can't see how JPA could possibly be returning a Character from a native query, it would just be calling getObject() on the JDBC ResultSet.

Please include the code on how you are executing the query, and include the JPA provider you are using (if you don't know, print em.getDelegate().getClass()).
Anand Parthasarathy
Greenhorn

Joined: May 23, 2011
Posts: 13
James,

The JPA provider is Hibernate.
We use a EJB which gets an instance of the EntityManager em. I am not sure of how they get the instance. Here is the code:



Regards,
-Anand

James Sutherland wrote:I can't see how JPA could possibly be returning a Character from a native query, it would just be calling getObject() on the JDBC ResultSet.

Please include the code on how you are executing the query, and include the JPA provider you are using (if you don't know, print em.getDelegate().getClass()).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JPA Native Query
 
Similar Threads
Calling stored procedures
HQL Doubt
Prepared statment executeQuery() error.
JDBC - Date
problem with Date in iBatis