简体   繁体   English

如何在JPARepository中编写内部联接查询

[英]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.

相关问题 使用 JpaRepository 进行内连接而不编写查询 - Inner join using JpaRepository without writing the query 如何在 hibernate.ejb 中编写内连接选定表查询 - how to write inner join a selected table query in hibernate.ejb 如何编写查询参数为列表的JPARepository查询? - How to write JPARepository query where a query parameter is a list? spring 启动,JpaRepository 自定义查询内部连接和查看 thymeleaf,连接列未显示 - spring boot, JpaRepository Custom query inner join and view on thymeleaf, joined column is not showing 嵌套的FETCH JOIN如何使用JpaRepository和@Query注释在Hibernate上工作? - How nested FETCH JOIN works on Hibernate using JpaRepository and @Query annotation? JpaRepository JOIN JPQL 查询 WITH Pageable 对象。 如何实施? - JpaRepository JOIN JPQL query WITH Pageable objects. How to implement? 在Hibernet 1中通过使用联接列完成许多映射如何使用该联接列编写HQL查询以创建内部联接 - in Hibernet 1 to many mapping done by using join column how write HQL query to create inner join using that join column Java JpaRepository @Query连接自己的表 - Java JpaRepository @Query join own table 带有jparepository的复杂查询。 三个表联接 - Complicated query with jparepository. Three tables join 在休眠中编写内部联接 - to write inner join in hibernate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM