queryStr.append("select new com.ewayit.model.Attrecord(p.id, p.attendanceDate, p.officetime_desc, p.closetime,") .append(" p.officetime, p.closetime_desc, p.latetime, p.earlytime, p.overtime, p.absenttime, p.holidays,") .append(" p.holiday, r.id, isnull(p.officeTimeType.id, 0) as officetime_id, isnull(p.closeTimeType.id, 0) as closetime_id, r.name, r.att_state, r.enNo)") .append(" from com.ewayit.model.Attendance p, com.ewayit.model.Record r where p.record.id = r.id"); 这是我的查询语句,但是出现的时候报了空指针异常。如果我去掉查询中的 isnull 函数的时候,查询没有问题。 我想把 p.officeTimeType.id 值为 null ,替换成 0。 求大神帮忙!!
给model 对应的字符赋个初始值试试。
private String id = "";
谢谢 ohogogo ! 在 modul 中对字段赋了一个初始值。已解决。
p.officeTimeType.id 所对应的是一个外键,数据类型是Integer,在Attrecord中的它的数据类型是int,在数据库主表中该字段有部分值是 null,查询的时候报如下错误: org.hibernate.QueryException: could not instantiate class [com.ewayit.model.Attrecord] from tuple; 所以我想在查询语句中对该字段为 null 值做个替换,替换为0。
.append(" p.officetime, p.closetime_desc, p.latetime, p.earlytime, p.overtime, p.absenttime, p.holidays,")
.append(" p.holiday, r.id, isnull(p.officeTimeType.id, 0) as officetime_id, isnull(p.closeTimeType.id, 0) as closetime_id, r.name, r.att_state, r.enNo)")
.append(" from com.ewayit.model.Attendance p, com.ewayit.model.Record r where p.record.id = r.id");
这是我的查询语句,但是出现的时候报了空指针异常。如果我去掉查询中的 isnull 函数的时候,查询没有问题。
我想把 p.officeTimeType.id 值为 null ,替换成 0。 求大神帮忙!!
org.hibernate.QueryException: could not instantiate class [com.ewayit.model.Attrecord] from tuple;
所以我想在查询语句中对该字段为 null 值做个替换,替换为0。