如何在JPARepository中编写内连接查询

时间:2017-06-14 12:07:02

标签: java mysql repository spring-data-jpa inner-join

我有以下查询在MySQL中完美运行但是当我在存储库中编写时它会出错我如何在JPARepository中编写内连接查询?

@Query("Select address from Address a inner join Order o ON a.id=o.pickup_address_id where o.customer_id=: customerId  AND a.address LIKE 'C%'")
     Set<Address> findPickupAddress(@Param("customerId") Long customerId); 

错误:意外令牌:在第1行第66列附近订购

2 个答案:

答案 0 :(得分:0)

order是保留字。如果你不能重命名表,你应该使用它:

@Query("Select address from Address a inner join `Order` o ON ...")

答案 1 :(得分:0)

JPQL中没有 @Query("Select a from Address a , Order o where a.id=o.pickupAddress AND o.customer.id=:customerId AND a.address LIKE 'C%'") Address findPickupAddress(@Param("customerId") Long customerId); } ,因此查询更新为:

AVPlayerController