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
?
@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
order
is a reserved word. 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 :
@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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.