日期:2014-05-17  浏览次数:20660 次

hibernate的一个查询问题
我现在有两张表,其中一张是中间表 主表为student 表示学生信息 另一张是中间表student_course 有student_ID 和 elective_courseID选修课ID还有status(是否及格) 现在我想查询出student这个的所有学生的List 其中student对象有个Set<electiveCourse>的属性,现在我要这个Set<electiveCourse>的status全是及格的  


------解决方案--------------------
hql语句:
select st from Student st left outer join fetch st.studentCourse cour where cour.status=1L;

------解决方案--------------------
class Student{
Set<electiveCourse> courses;
}
实体类一对多的关系要定义好

session.createCriteria(Student.class).createCriteria("courses").add(Restrictions.eq("status", 及格)).list()

或者用Restrictions.sqlRestriction

或者hql