spring-data-jpa 无法使用单向@OneToMany关系JPA提取记录

gdrx4gfi  于 2022-11-10  发布在  Spring
关注(0)|答案(1)|浏览(152)

我无法使用JPA中的单向@OneToMany关系来获取记录。知道是否缺少了什么吗?记录正在被持久化;只有检索记录有问题。

class Employee{

    int empId;
    ...
    @OneToMany(cascade = ALL, mappedBy = "deptId",fetch = FetchType.EAGER)
    List<Department> departments=new ArrayList<>();

    //getters and setters

}

class Department{

    String code;
    ....
    int deptId;

    //getters and setters

}

empRepository.findById(empId).getDepartments(); // is not returning rows even if records are available.

相关问题