Hibernate3 回到查询结果为Map时 ,有的字段只返回第一位字符
Hibernate3 返回查询结果为Map时 ,有的字段只返回第一位字符??????? Hibernate3 返回查询结果为Map时 ,有
Hibernate3 返回查询结果为Map时 ,有的字段只返回第一位字符?
?????? Hibernate3 返回查询结果为Map时 ,有的字段只返回第一位字符?返回结果,HashMap KEY DM ,VALUE 总把结果截断,返回第一个字符。
?
public static List geDmList(){? ?? ?? ?? ?JbpmConfiguration jbpmConfiguration = JbpmFactory.createJbpmConfiguration();? ?? ?? ?? ?JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();? ?? ?? ?? ?? ???List result = null;? ?? ?? ?? ?? ?? ???try {? ?? ?? ?? ?? ?? ?? ? Query query??= jbpmContext.getSession().createSQLQuery("select dm,mc from t_dm").setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);????????????????????? System.err.println("dm="+((HashMap)result.get(0)).get("DM"));? ?? ?? ?? ?? ?? ?? ? result = query.list();? ?? ?? ?? ?? ?? ???} catch (Exception e) {? ?? ?? ?? ?? ?? ?? ? throw new JbpmException("errmsg", e);? ?? ?? ?? ?? ?? ???} finally {? ?? ?? ?? ?? ?? ?? ?? ?? ? jbpmContext.close();? ?? ?? ?? ?? ?? ???}? ?? ?? ?? ?? ?? ???return result;? ?? ???? ? }
"select dm,mc from t_dm"
改为:
"select cast(dm as varchar2(10)) dm,mc from t_dm"
?
经过测试:
?????? 在oracle或sqlServer下会遇到,查询数据表字段类型为char,如果使用Hibernate原生SQL去执行查询,往往只会返回一个字符.原因是char在java中只有两个字节。
?
解决方法
1.改成
?? select cast(列 as varchar2(列大小)) from 表;或者改为 select trim(列) from 表
?
2.指定列返回的类型.
SQLQuery query = session.createSQLQuery();?
query.addScalar(columnAlias,Type);
?
?
转载:
http://www.itpub.net/forum.php?mod=viewthread&tid=1610132
http://blog.csdn.net/FZfeng/article/details/5875964