为什么同样方式自定义类型,有的可以,有的不可以

来源:5-5 通过自定义类型返回查询结果

爆冷

2017-04-14 08:07

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)";

这个却没有报错

写回答 关注

2回答

  • XhstormR
    2017-05-20 17:49:50

    你好,解决了吗???

  • 慕粉0854044765
    2017-04-16 13:22:44

    先问一个问题,你试过没有,这样的查询条件是否能够查到数据,也存在筛选条件下没有数据的情况。

HQL数据查询基础

使用HQL从数据库中找到你要的数据,掌握了使用Hibernate

41151 学习 · 90 问题

查看课程

相似问题