简体   繁体   English

如何在休眠状态下使用条件多对多单向关联获取列表?

[英]How to fetch list using Criteria Many to Many unidirectional association in hibernate?

I have two Entity classes which possess many to many uni directional association.Here is my full code. 我有两个Entity类,它们具有多对多的单向关联。这是我的完整代码。 What would be query if I want to fetch list of students which have same course like English ? 如果我想获取与英语课程相同的学生名单,该怎么办? I have no getter setter of list of student in Courses Entity because I am using unidirectional many to many relationship . 我没有课程实体中学生列表的设置程序,因为我使用的是单向多对多关系。 Please help me. 请帮我。

@Entity
    @Table(name = "course")
    public class Courses {
        @Id
        @Column(name = "sid")
        @GeneratedValue(generator = "uuid")
        private String id;

         //other getters setters
    }


    @Entity
    @Table(name = "student")
    public class Student {
        @Id
        @Column(name = "sid")
        @GeneratedValue(generator = "uuid")
        private String id;
    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
        @JoinTable(name = "stu_cou", joinColumns = {@JoinColumn(name = "sid", nullable = false)}, inverseJoinColumns = { @JoinColumn(name = "cid", nullable = true) })
        private List<Courses> courses;
    }

You could use a NamedQuery in your Courses Entity with a join. 您可以在课程实体中通过联接使用NamedQuery。

See here . 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM