ManyToMany 的 JPA 标准规范

JPA Criteria Specification for ManyToMany

我的实体 ClientAgency 具有 ManyToOne 关系,因此 table client 的列 agency_id 指向 table agency,还有 Client 有:

@ManyToOne
@JoinColumn(name = "agency_id")
private Agency agency;

Spring select ClientAgency id 在:

中有 Spring 数据 JPA 规范
public static Specification<Client> withAgencyIds(Collection<Long> agencyIds) {
    return (root, query, cb) -> root.join(Client_.agency).get(Agency_.id).in(agencyIds);
}

现在我必须将 ManyToOne 关系更改为 ManyToMany 关系,以便 Client 具有:

@ManyToMany
@JoinTable(name = "client_agency",
           joinColumns = @JoinColumn(name = "client_id"),
           inverseJoinColumns = @JoinColumn(name = "agency_id"))
@OrderBy("name")
private List<Agency> agencies = new ArrayList<>();

我应该如何调整上述规范才能使 select Client 具有 Agency id?

非常感谢您!

这个 JPA 标准规范工作正常:

public static Specification<Client> withAgencyIds(Collection<Long> agencyIds) {
    return (root, query, cb) -> root.join(Client_.agencies).get(Agency_.id).in(agencyIds);
}