如何为此 sql 查询编写 Hibernate 条件?
How to write Hibernate Criteria for this sql Query?
我有一个这样的查询
查询
SELECT attendance_entry.roll_no,attendance_entry.absent_date,attendance_entry.absent_status,attendance_entry.leave_status,attendance_entry.od_status
FROM attendance,attendance_entry
WHERE attendance.class_id='"+classId+"' &&
attendance.section_id='"+sectionId+"' &&
attendance_entry.absent_date= STR_TO_DATE('"+date+"','%a %b %d %H:%i:%s IST %Y')
GROUP BY attendance_entry.roll_no";
我需要编写条件来解析 Json
我尝试了以下标准
Criteria cr = getSession().createCriteria(AttendanceEntry.class)
.setProjection(Projections.projectionList()
.add(Projections.property("rollno"),"rollno")
.add(Projections.property("absent"),"absent")
.add(Projections.property("leave"),"leave")
.add(Projections.property("od"),"od")
.add(Projections.groupProperty("rollno"),"rollno"))
.add(Restrictions.eq("attendance.classYear.id", classId))
.add(Restrictions.eq("attendance.section.id", sectionId))
.add(Restrictions.eq("absentDate", date))
.setResultTransformer(Transformers.aliasToBean(AttendanceEntry.class));
return cr.list();
而且我遇到以下错误
错误
could not resolve property: attendance.classYear.id of: com.technofolks.model.AttendanceEntry; nested exception is org.hibernate.QueryException: could not resolve property: attendance.classYear.id of: com.technofolks.model.AttendanceEntry
我已将出勤和进入映射为一对多和多对一。如何编写条件查询?
这个标准适用于我的 MySQL 查询
@Override
@Transactional
@SuppressWarnings("unchecked")
public List<AttendanceEntry> getAttendanceByDateSearch(String classId, String sectionId, Date date) {
Criteria cr = getSession().createCriteria(AttendanceEntry.class,"attendanceEntry")
.createAlias("attendanceEntry.attendance","attendance")
.setProjection(Projections.projectionList()
.add(Projections.property("rollno"),"rollno")
.add(Projections.property("absent"),"absent")
.add(Projections.property("leave"),"leave")
.add(Projections.property("od"),"od")
.add(Projections.property("absentDate"),"absentDate")
.add(Projections.groupProperty("rollno"),"rollno"))
.add(Restrictions.eq("attendance.classYear.id", classId))
.add(Restrictions.eq("attendance.section.id", sectionId))
.add(Restrictions.eq("absentDate", date))
.setResultTransformer(Transformers.aliasToBean(AttendanceEntry.class));
return cr.list();
}
我有一个这样的查询
查询
SELECT attendance_entry.roll_no,attendance_entry.absent_date,attendance_entry.absent_status,attendance_entry.leave_status,attendance_entry.od_status
FROM attendance,attendance_entry
WHERE attendance.class_id='"+classId+"' &&
attendance.section_id='"+sectionId+"' &&
attendance_entry.absent_date= STR_TO_DATE('"+date+"','%a %b %d %H:%i:%s IST %Y')
GROUP BY attendance_entry.roll_no";
我需要编写条件来解析 Json
我尝试了以下标准
Criteria cr = getSession().createCriteria(AttendanceEntry.class)
.setProjection(Projections.projectionList()
.add(Projections.property("rollno"),"rollno")
.add(Projections.property("absent"),"absent")
.add(Projections.property("leave"),"leave")
.add(Projections.property("od"),"od")
.add(Projections.groupProperty("rollno"),"rollno"))
.add(Restrictions.eq("attendance.classYear.id", classId))
.add(Restrictions.eq("attendance.section.id", sectionId))
.add(Restrictions.eq("absentDate", date))
.setResultTransformer(Transformers.aliasToBean(AttendanceEntry.class));
return cr.list();
而且我遇到以下错误
错误
could not resolve property: attendance.classYear.id of: com.technofolks.model.AttendanceEntry; nested exception is org.hibernate.QueryException: could not resolve property: attendance.classYear.id of: com.technofolks.model.AttendanceEntry
我已将出勤和进入映射为一对多和多对一。如何编写条件查询?
这个标准适用于我的 MySQL 查询
@Override
@Transactional
@SuppressWarnings("unchecked")
public List<AttendanceEntry> getAttendanceByDateSearch(String classId, String sectionId, Date date) {
Criteria cr = getSession().createCriteria(AttendanceEntry.class,"attendanceEntry")
.createAlias("attendanceEntry.attendance","attendance")
.setProjection(Projections.projectionList()
.add(Projections.property("rollno"),"rollno")
.add(Projections.property("absent"),"absent")
.add(Projections.property("leave"),"leave")
.add(Projections.property("od"),"od")
.add(Projections.property("absentDate"),"absentDate")
.add(Projections.groupProperty("rollno"),"rollno"))
.add(Restrictions.eq("attendance.classYear.id", classId))
.add(Restrictions.eq("attendance.section.id", sectionId))
.add(Restrictions.eq("absentDate", date))
.setResultTransformer(Transformers.aliasToBean(AttendanceEntry.class));
return cr.list();
}