小编典典

多对多查询jpql

java

我遇到了麻烦。

有一个实体发行人与与实体镇的ManyToMany关系有关:

@Entity
public class Distributor{

   @ManyToMany
   @JoinTable( name = "GS_DISTRIBUTOR_TOWN",
           joinColumns = @JoinColumn(name = "CD_DISTRIBUTOR"),
           inverseJoinColumns = @JoinColumn(name = "CD_TOWN") )
   private List<Town> towns;

   ....
}

那么实体镇也与地区有关

@Entity
public class Town{

   @ManyToMany(mappedBy="towns")
   private List<Distributor> distributors;

   @ManyToOne
   private District district;

   ....
}

现在,我必须过滤(使用jpql)一个区域中的所有分发服务器。我能怎么做?


阅读 256

收藏
2020-12-03

共1个答案

小编典典

select distinct distributor 
from Distributor distributor  
join distributor.towns town 
join town.district district 
where district.name = :name

请参阅:https//en.wikibooks.org/wiki/Java_Persistence/JPQL

2020-12-03