我有麻烦。

有一个实体发行人与与实体镇的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)一个区域中的所有分发服务器。
我能怎么做?

最佳答案

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

09-05 11:41