我有一个存储库public interface GroupRepository extends JpaRepository<Group, Integer> {}该组确实有一个项目清单private List<Item> items;每个Item都有一个position属性private int position;如何通过知道其中一个列表中存在的项目的位置来检索组 ?项目.javapublic class Item extends PersistedBean{ private int position; private Group group; @Column(name = "Position") public int getPosition() { return position; } @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "GroupId", referencedColumnName = "Id") public Group getGroup() { return group; }}组.javapublic class Group extends PersistedBean { private int position; private List<Item> items; @Column(name = "Position") public int getPosition() { return position; } @OneToMany(cascade = CascadeType.ALL, mappedBy = "group", orphanRemoval = false) public List<Item> getItems() { return items; }}
1 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
您可以将查询添加到您的JpaRepository<Group, Integer>存储库,类似于应该工作:
@Query("SELECT g FROM Group g " +
"JOIN g.items i ON i.position IN :p")
List<Group> getGroupsWhenPositionMatchAnyRelatedItem(@Param("p") Integer p);
添加回答
举报
0/150
提交
取消