hibernate用原生的sql返回的数据不完整

drongHua 发布于 2016/05/07 16:30
阅读 161
收藏 0

@boonya 你好,想跟你请教个问题:

我用原生的sql

String sql= "select distinct data0050.customer_part_number+cp_rev ,data0494.parameter_value,"+
        " data0025.MANU_PART_NUMBER,data0278.PARAMETER_DESC,data0494.parameter_ptr from "+
        " data0025 inner join data0038 on data0025.rkey=data0038.source_ptr "+
        " inner join data0034 on data0034.rkey=data0038.dept_ptr "+
        " inner join data0494 on data0494.route_step_ptr=data0038.rkey inner join data0050 on data0050.rkey=data0025.ancestor_ptr "+
        " inner join data0059 on data0050.rkey=data0059.cust_part_ptr inner join data0010 on data0010.rkey=data0059.customer_ptr "+
        " inner join data0278 on data0494.parameter_ptr=data0278.rkey "+
        " where  data0050.customer_part_number+cp_rev = ? and "+
        " (data0034.dept_name like ? or data0034.dept_name like ? or data0034.dept_name like ?) order by data0494.parameter_ptr";


SQLQuery query = getSession2().createSQLQuery(sql);
query.setParameter(0, "GHS10K05500b0");
query.setParameter(1, "锣板1");
query.setParameter(2, "锣板2");
query.setParameter(3, "锣板3");
List<Object[]> list = query.list();
for (int i = 0; i < list.get(0).length; i++) {
System.out.println(i+" = "+list.get(0)[i]+" len="+list.get(0)[i].toString().length());
}
输出的结果如下:

0 = GHS10K05500B0 lenl=13
1 = 是 lenl=1
2 = GHS10K05500 lenl=11
3 = 是 lenl=1
4 = 98 lenl=2

但是,我在sql server 2008后台执行时,结果是这样的,我不知为什么,程序取出来的,第3个元素就只有一个"是"

加载中
0
drongHua
drongHua
已经搞定了,用SQLQuery query = getSession2().createSQLQuery(sql)
.addScalar("MANU_PART_NUMBER", StringType.INSTANCE)
.addScalar("parameter_value", StringType.INSTANCE)
.addScalar("PARAMETER_DESC", StringType.INSTANCE)

.addScalar("parameter_ptr", StringType.INSTANCE);

就可以了

返回顶部
顶部