在线等,hibernate的sql查询
我从一张表之中查3个字段
查完之后这3个字段组合为一个对象
现在想查询这个对象的list,该如何做呢?
public List<NormalKaoQin> getNormalKaoQinList() {
Session s = this.getSession();
List list = s.createSQLQuery("select cio1.userid,cio1.checktime,cio2.checktime " +
"from checkinout cio1,checkinout cio2 " +
"where cio1.userid = cio2.userid " +
"and cio1.checktype='I' " +
"and cio2.checktype='O' " +
"and year(cio1.checktime) = year(cio2.checktime) " +
"and month(cio1.checktime) = month(cio2.checktime) " +
"and day(cio1.checktime) = day(cio2.checktime);").addEntity(NormalKaoQin.class).list();
return list;
}
for(int i = 0 ; i < list.size(); i ++){
/*
* 数组元素顺序跟sql中字段的顺序一致、从0开始
*/
Object[] objarr = (Object[])list.get(i);
System.out.println(objarr[0]); //cio1.userid
System.out.println(objarr[1]); //cio1.checktime
System.out.println(objarr[2]); //cio2.checktime
}