我有一個名為“員工”的實體,它與自己有聯(lián)系。聯(lián)接表示誰是該員工的經(jīng)理。當(dāng)我查詢記錄時,我得到了員工的整個層次結(jié)構(gòu)。我希望實現(xiàn)的是只獲取經(jīng)理的幾個字段,而不希望獲取員工的經(jīng)理的經(jīng)理。我嘗試使用但無法獲得預(yù)期的輸出來執(zhí)行此操作。也使用過。@NamedEntityGraphProjections我還嘗試了這里提到的方法JPA 使用連接表進(jìn)行自連接自加盟春聯(lián)歡注意 - 我不想使用注釋@Query@Entitypublic class Employee { @Id @Column(name = "employeeId", nullable = false) private String employeeId; @Column(name = "firstName", nullable = false) private String firstName; @Column(name = "lastName", nullable = false) private String lastName; @Column(name = "middleName") private String middleName; @Column(name = "dateOfJoining", nullable = false) private LocalDate dateOfJoining; @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "line_manager_id") private Employee manager;}實際結(jié)果 -{ "firstName":"Super", "lastName":"Manager", "middleName":"", "dateOfJoining":"2012-12-31", "manager":{ "firstName":"Super", "lastName":"Manager", "middleName":"", "dateOfJoining":"2012-12-31", "manager":{ "firstName":"Admin", "lastName":"User", "middleName":"", "dateOfJoining":"2012-12-31", "manager":{ "firstName":"Admin", "lastName":"User", "middleName":"", "dateOfJoining":"2012-12-31", "manager": null, "employeeId":"P67" }, "employeeId":"P68" }, "employeeId":"P69" }, "employeeId":"P70"}預(yù)期成果{ "firstName":"Super", "lastName":"Manager", "middleName":"", "dateOfJoining":"2012-12-31", "manager":{ "firstName":"Super", "lastName":"Manager", "employeeId":"P69" }, "employeeId":"P70"}
添加回答
舉報
0/150
提交
取消