Jpql multiuser query

I have the following issues.

There is a distributor of the organization, which is associated with the attitude of ManyToMany to the city of persons:

@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 city of the object also refers to the county

 @Entity public class Town{ @ManyToMany(mappedBy="towns") private List<Distributor> distributors; @ManyToOne private District district; .... } 

Now I have to filter (with jpql) all the distributors who are in the county. How can i do this?

+15
source share
1 answer
 select distinct distributor from Distributor distributor join distributor.towns town join town.district district where district.name = :name 

See: https://en.wikibooks.org/wiki/Java_Persistence/JPQL

+31
source

Source: https://habr.com/ru/post/953058/


All Articles