• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA Native Query

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anand Parthasarathy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()).

 
I AM MIGHTY! Especially when I hold this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic