◎筱米加步枪◎.Blog

Happy coding

Oracle中char类型字段在Hibernate中SQL查询只返回一个字符 解决方法

筱米加步枪 posted @ 2011年9月07日 15:21 in [ 开源框架 ] with tags Hibernate char , 5380 阅读

场景如下:

使用char(2)的类型来标识某个类型,比如01,02,03...

结果使用Hibernate的SQL查询该字段只返回0,0,0...

跟踪发现,char类型映射出Java对象是Character,说明char在Java中只有两个字节(一个字符),因此只返回0

解决方法:

通过限定他的返回类型为String就行了,如下:

SQLQuery query = session.createSQLQuery(sql);

query.addScalar("列名",Hibernate.STRING);

即可解决.不过会导致对所查询的字段都要加上addScalar.

Online CUB 说:
2022年8月05日 03:01

City Union bank is a private authorized bank in India that provides various facilities to its account holders. With the growing banking structure, Online CUB change in dynamics, and number of private players entering in the banking sector of India. This will change work culture, competitive environment, a customer also requires their banking services at their doorsteps.Gone are the days, when people used to stand in the queues for transactions, balance check, or money transfers. Therefore, like other banks in India, City union bank also provides its users with the Online banking facility.

jnanabhumiap.in 说:
2024年1月18日 21:01

JNANABHUMI AP provides all the latest educational updates and many more. The main concept or our aim behind this website has been the will to provide resources with full information on each topic jnanabhumiap.in which can be accessed through the Internet. To ensure that every reader gets what is important and worthy about the topic they search and link to hear from us.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter