开发者

strange hibernate createSQLQuery returns a CHAR|Character but String

I am using hibernate createSQLQuery, but it returns only first char.

tableName = 'select code, name from airports where excludeFromSearch = 0 order by name';
s.createSQL开发者_如何学GoQuery(tableName).list();

I am using:

  • Mysql
  • hibernate 3.2

Snapshot:

strange hibernate createSQLQuery returns a CHAR|Character but String

I have googled stackoverflow,forum.hibernate,atlassian

UPDATE: i have also checked all hibernate query log and even mysql query log both are same.

`code char(3)`  // <strike>might</strike> must cause problem as in screen shot
name varchar(100)


Have you tryied to set Scalar to your request?

StringType stringTypeInstance = StringType.class.newInstance();

String tableName = 'select code, name from airports where excludeFromSearch = 0 order by name';

List<Object[]> result = s.createSQLQuery(tableName)
    .addScalar("code",stringTypeInstance)
    .addScalar("name",stringTypeInstance )
    .list();


First, try to fire the query that is generated by hibernate, on the database, and then try to match the results. If the query on database is also returning the same result, then check your table definition, the code is really string or something else.

And better option for writing queries that to SQL queries will be to write them, in the hbm file, and then define return properties in it, that will help you a lot, as then u will be able to covert the output into desired objects, not the array of object.


You can do simple convert in SQL statement.

select convert(varchar, Name) from Person

Problem exists in older versions of Hibernate when char is autowired to Character column value. https://hibernate.atlassian.net/browse/HHH-2304

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜