JPQL ManyToMany select

前端 未结 1 975
南旧
南旧 2020-12-29 10:31

I have a Many To Many relationship between two entities called: Car and Dealership.

In native MySQL I have:

car (id and other values)
dealership (id          


        
1条回答
  •  -上瘾入骨i
    2020-12-29 11:12

    select car from Car car 
    inner join car.dealerships dealership
    where dealership in :dealerships
    

    The parameter must be a collection of Dealership instances.

    If you want to use a collection of dealership IDs, use

    select car from Car car 
    inner join car.dealerships dealership
    where dealership.id in :dealershipIds
    

    Remamber that JPQL always use entities, mapped attributes and associations. Never table and column names.

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