[英]How to write inner join query in JPARepository
I have the following query which runs perfectly in MySQL but it gives an error when I written in repository How can I write inner join query in JPARepository
? 我有以下查询,该查询可以在MySQL中完美运行,但是在存储库中编写时却给出了错误。如何在
JPARepository
编写内部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);
Error : unexpected token: Order near line 1, column 66 错误:意外令牌:第1行第66列附近的订单
order
is a reserved word. order
是保留字。 If you can't rename the table you should use it like: 如果您不能重命名该表,则应按以下方式使用它:
@Query("Select address from Address a inner join `Order` o ON ...")
There is no ON
in JPQL so the query is updated as : JPQL中没有
ON
,因此查询更新为:
@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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.