我在从这个类中检索一些信息时遇到问题。
@Entity
public class Absence {
@Id @GeneratedValue(strategy= GenerationType.IDENTITY)
private int absenceId;
private int crn;
private int studentId;
@Temporal(TemporalType.DATE)
private Date absenceDate;
}
我想检索以下信息:studentId,学生姓名,缺席人数。查询不起作用的问题。 我正在使用的查询是
public List<StudentAbsenceSummary> getSetionAbsences(int crn) {
Query q=em.createQuery("select b.studentId,count(b.studentId) from Absence b where b.crn =:crn group by (b.studentId)")
.setParameter("crn", crn);
List<StudentAbsenceSummary> students =q.getResultList();
return students;
}
检索到的列表的类
public class StudentAbsenceSummary {
private int studentId;
private String name;
private int absenceCount;