/////实体1
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name="po_publicOpinion_unitCounties",
joinColumns=
@JoinColumn(name="publicOpinion_id", referencedColumnName="id"),
inverseJoinColumns=
@JoinColumn(name="unitCounties_id", referencedColumnName="id")
)
private List<UnitCounties> unitCounties; //////join的字段
////////////实体2
@ManyToMany(mappedBy = "unitCounties",fetch = FetchType.EAGER)
@JsonIgnore
private List<PublicOpinion> publicOpinions;
hql查询
"SELECT count(o) from PublicOpinion o join o.unitCounties u where u.id=1";