【发布时间】:2020-06-25 05:13:27
【问题描述】:
我的 Spring Boot 应用程序中有 Way POJO,如下所示:
public class Way {
@Id
private Long wayID;
@ToString.Exclude
@JsonIgnore
@ManyToMany(fetch = FetchType.LAZY,cascade=CascadeType.ALL)
private List<Relation> relations=new ArrayList<>();
现在我想选择所有具有给定值的关联 ID 的方式。
relationID 是Relation 的成员 POJO。
所以这是我的查询
@Query("select w from Way w join Relation relations where relations.relationID=?1")
List<Way> selectAllWaysByRelationID(Long relationID);
但错误似乎在我的JOIN 部分,它崩溃并说:
org.springframework.dao.InvalidDataAccessResourceUsageException:无法准备语句; SQL [select way0_.wayid as wayid1_5_ from way way0_内连接关系relation1_ on where relation1_.relationid=?];嵌套异常是 org.hibernate.exception.SQLGrammarException: could not prepare statement
我该如何解决这个问题?
我也试过这个:
@Query("select way from Way.relations full join Way.relations rel where rel.relationID=?1")
List<Way> selectAllWaysByRelationID(Long relationID);
这也是:
@Query("select way from Way way join Way.relations rel where rel.relationID=?1")
List<Way> selectAllWaysByRelationID(Long relationID);
【问题讨论】:
标签: spring spring-boot jpa spring-data-jpa