【发布时间】:2015-08-17 07:47:54
【问题描述】:
假设我有 A 类和 B 类
public class A{
@Id
String id;
private B b;
}
public class B{
@Id
String id;
private List<A> a;
}
我正在使用@Query进行查询,因为我的查询对于创建查询来说太长了。
@Query("select a from A a where b = :b")
public List<A> findSomething(@Param("b") String bId);
但是,当我使用该查询时,它会显示
Parameter value did not match expected type [B (n/a)]
【问题讨论】:
-
您声明的 B 是一个对象,而您传递的 b 是一个 Id。
-
我尝试使用 b.id,因此查询更改为
@Query("select a from A a where b.id = :b") public List<A> findSomething(@Param("b") String bId);但是它显示operator does not exist: character varying = bytea -
你能否用表结构更新问题,因为可能外键错误。使用 Hibernate 时,外键应始终指向另一个表的 id(主键)。如果不是这样,那将是您在 cmets 中提到的问题
-
不应该是
a.b.id而不是b.id吗?
标签: spring hibernate jpa spring-data spring-data-jpa