Many-to-Many query jpql

前端 未结 2 760
天涯浪人
天涯浪人 2021-02-01 03:56

I have the followed trouble.

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

@Entity
public class Distri         


        
相关标签:
2条回答
  • 2021-02-01 04:43

    First, from the entity Town, there is incorrect relationship mapping for @Manytoone. Should be:

    @Entity
    public class District {
    
      .....
    
       @ManyToOne
       private Town town;
    
       ....
    }
    
    0 讨论(0)
  • 2021-02-01 04:53
    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

    0 讨论(0)
提交回复
热议问题