Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 休眠OneToMany关系无法获取子项_Hibernate_Jpa - Fatal编程技术网

Hibernate 休眠OneToMany关系无法获取子项

Hibernate 休眠OneToMany关系无法获取子项,hibernate,jpa,Hibernate,Jpa,我对hibernate还不熟悉,正在努力学习基础知识。我正在尝试实现oneToMany映射,但在发出get请求时遇到问题。基本上,响应不显示子实体 public class Student implements Serializable { @Id @GeneratedValue private int id; private String name; @OneToMany(cascade = Cascade

我对hibernate还不熟悉,正在努力学习基础知识。我正在尝试实现oneToMany映射,但在发出get请求时遇到问题。基本上,响应不显示子实体

 public class Student implements Serializable {

        @Id
        @GeneratedValue
        private int id;

        private String name;

        @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
        Set<Course> courseList;
    }

 public class Course {

        @Id
        @GeneratedValue
        private int id;

        private String name;

}
注意:在调试中,我可以看到子实体已填充。但回应并不包括这一点


注2:此外,我想知道为什么hibernate在我使用fetchType时创建相同的sql(第二个用于获取子实体的sql)。出于测试目的,LAZY

尝试使用entityManager执行一个简单的查询
em.find(Student.class,studentId)
并查看实体完成该代码后将生成什么查询?如果是的话,这是行不通的。如果没有,请提供完整代码。如果你想让它工作,你必须定义完整的关系。您需要两个实体之间的映射,这显然是缺失的。这里只有构造函数、setter和getter。为什么缺少映射?在调试模式下,我可以看到对象正确地填充了子实体。Anc我可以访问它们。只有JSON响应不包含它。
 select
        student0_.id as id1_1_,
        student0_.name as name2_1_ 
    from
        students student0_


select
        courselist0_.student_id as student_1_2_0_,
        courselist0_.course_list_id as course_l2_2_0_,
        course1_.id as id1_0_1_,
        course1_.name as name2_0_1_,
        course1_.student_id as student_3_0_1_,
        student2_.id as id1_1_2_,
        student2_.name as name2_1_2_ 
    from
        students_course_list courselist0_ 
    inner join
        courses course1_ 
            on courselist0_.course_list_id=course1_.id 
    left outer join
        students student2_ 
            on course1_.student_id=student2_.id 
    where
        courselist0_.student_id=?