【问题标题】:Parameter value did not match expected type (Spring Data JPA)参数值与预期类型不匹配(Spring Data JPA)
【发布时间】: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&lt;A&gt; 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


【解决方案1】:

请将查询更改为“从 A a where a.b.id = :b 中选择 a”。它会工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    • 2022-01-08
    • 2014-06-09
    • 2019-03-13
    • 1970-01-01
    • 2021-08-05
    相关资源
    最近更新 更多