本文介绍了多对多查询jpql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了麻烦.

有一个实体分发服务器,该分发服务器与ManyToMany与实体城镇的关系有关:

There is an entity Distributor who is connected with the ManyToMany relationship to entity town:

@Entity
public class Distributor{

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

   ....
}

然后实体镇也与地区有关

Then the entity town is also in relation with District

@Entity
public class Town{

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

   @ManyToOne
   private District district;

   ....
}

现在,我必须过滤(使用jpql)位于一个区域中的所有分发服务器.我该怎么办?

Now i have to filter(with jpql) all distributor who are in a district.How can i do?

推荐答案

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

这篇关于多对多查询jpql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:14