参数值与预期类型不匹配(Spring Data JPA)

时间:2022-07-25 20:04:32

Let's say I have class A and B

假设我有A类和B类

public class A{
@Id
String id;
private B b;
}

public class B{
@Id
String id;
private List<A> a;
}

I'm using @Queryfor my query since my query is too long for Query creation .

我使用@Queryfor查询,因为查询太长,无法创建查询。

@Query("select a from A a where  b = :b")
public List<A> findSomething(@Param("b") String bId);

However, when I use that query it shows

然而,当我使用该查询时,它会显示出来

Parameter value  did not match expected type [B (n/a)]

1 个解决方案

#1


2  

Please change query to "select a from A a where a.b.id = :b". It will work

请将查询改为“a, a, a, a, b”。id =:b”。它将工作

#1


2  

Please change query to "select a from A a where a.b.id = :b". It will work

请将查询改为“a, a, a, a, b”。id =:b”。它将工作