I am using annotion to map the entity to table, but meet this problem. Exception "argument type mismatch" rised when a String property map a character column in db2 by using org.hibernate.transform.ResultTransformer, here is the code which will rise exception:
String sql = "select id, name from table1"; SQLQuery sq = session.createSQLQuery(sql); sq.setResultTransformer(Transformers.aliasToBean(XXVO.class)); return sq.list();
The id's data type is character(length 26), the name's is varchar, and I have String property "id" and "name" in entity XXVO. In the code above, actually Hibernate use org.hibernate.transform.AliasToBeanResultTransformer to map the tuple get from ResultSet to property of entity XXVO. I found that the mapping of "name" is ok, but for the mapping of "id", I see that the tuple is a java.lang.Character instance, not String. And the value of tuple is the first char of the real value of "id". So that's why the exception arise.
But when I was using SQLQuery.addEntity instead of the org.hibernate.transform.ResultTransformer, the mapping between property and column is ok, here is the code which do not rise exception:
String sql = "select * from table1"; SQLQuery sq = session.createSQLQuery(sql); sq.addEntity(XXVO.class); return sq.list();
Is it the bug of Hibernate? Thanks for help!
|