java – Hibernate条件查询多个条件

在我目前的项目中,我遇到了使用hibernate条件查询获取实体的问题.我有以下实体:

>教授,其中包含学生名单
>学生,其中包含作业列表.
>分配,包含分配给它的学生的ID.

现在,我希望获得与教授相关的所有作业,即教授分配给他的学生的所有作业.

查询显示我要在条件查询中实现的内容.

select * from Assigment p,Student a,Professor c where p.studentid = a.id and a.proffid = c.id and c.id = 2411;

如何使用hibernate criteria API实现此查询

最佳答案
假设你的表是这样的:

@Entity
public class Professor{
    K id;
    List

使用别名的简单示例:

Criteria criteria = currentSession.createCriteria(Professor.class,"professor");
    criteria.createalias("professor.students","student");
    criteria.createalias("student.assigments","assigment");
    criteria.add(Restrictions.eqProperty("professor.id","student.profid"));
    criteria.add(Restrictions.eqProperty("assigment.studentid","student.profid"));
    criteria.add(Restrictions.eq("id",2411));
return criteria.list();

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...