为什么同样方式自定义类型,有的可以,有的不可以
public DayDataDTO(String sid, double distance, long steps, double speed,
double calories, long date) {
super();
this.sid = sid;
this.distance = distance;
this.steps = steps;
this.speed = speed;
this.calories = calories;
this.date = date;
}
hql="select new dto.DayDataDTO(sid,sum(distance) as distance,sum(steps) as steps,AVG(speed) as speed,sum(calories) as calories, sum(date) as date) from Score"
+ " where sid='"+sid+"' and date_format(uploadtime,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') GROUP BY DAY(uploadtime)";
上面就会报错
java.lang.NullPointerException
at org.hibernate.internal.util.ReflectHelper.getConstructor(ReflectHelper.java:355)
而下面的呢,
public DataDTO(long steps, Date uploadtime) {
super();
this.steps = steps;
this.uploadtime = uploadtime;
}
}
hql="select new dto.DataDTO( sum(steps),uploadtime) from Score where sid='"+sid +"' and"
+ " YEARWEEK(DATE_FORMAT(uploadtime,'%y-%m-%d'))=YEARWEEK(NOW()) GROUP BY DAY(uploadtime)";
这个却没有报错