-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA native query mapping of CHAR(3) truncates to 1 char
PostPosted: Wed Aug 31, 2011 4:15 pm 
Newbie

Joined: Wed Aug 31, 2011 3:33 pm
Posts: 5
A native SQL query returning currency codes (e.g. "USD", "EUR", "JPY") stored in a column as CHAR(3) returns the first character only because the result column is mapped to char Java type.

Anybody knows if this a bug or a feature? Can it be overriden by registerTypeOverride ? cannot find anything corresponding to addScalar in JPA.

Example:
Code:
      Query q = em.createNativeQuery("select Currency, Amount from Item where ..... ");
      for (Object[] i : (List < Object [] > ) q.getResultList()) {
                        // i[0] is of type 'char', and contains the first letter of the actual currency code, e.g. 'U' for "USD"
      }


Running Jboss AS7 and Hibernate 4.0.0Beta5 on MySQL 5.1. Also found a workaround doing
Code:
"select convert(Currency, char(4)), Amount ..."
which surprisingly returns a string instead (guess MysQL / JDBC type turns varchar), but it feels less than stable.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.