• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't read with native query a type of CHAR

 
dinesh thalis
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working with mysql 5.1 / glassfish v2 .1 /EJB3/JDK6
I want from a nativequery read a field of CHAR(n) in a database, when I user varchar , it s works, but if i use char(n), I always get a Character instead of a String.

When i user native query to retrive data then I get a java.lang.Character instead of a String.



How can solve this. please help me if this can't i have to change whole database architecture. Therefore I should do this.
 
Jackie Li
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems native query treat char as Character.
solution1: use query.unwrap(SQLQuery.class)
solution2: simply cast the column to varchar, cast(LAE.legalAccessEntityCode as varchar(12))
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What JPA provider are you using? Sounds like a bug.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic