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.