抛出操作数的子句中的 Spring JPA 应包含 1 列

Pas*_*kam 2 java mysql hibernate spring-data-jpa spring-boot

我正在使用 spring JPA 在 MySql 数据库上进行选择操作

桌子

select id, grp, name from student;

存储库方法

List<Student> findByGrpAndName(String grp, Set<String> name);

它在扔

java.sql.SQLException: Operand should contain 1 column(s) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)

我尝试调试 hibernet 代码以查看创建的查询。并且查询有语法错误。

select student0_.name as name1_1_, student0_.grp as grp2_1_ from student student0_ where student0_.grp=? and student0_.name=(? , ?);

它应该是 student0_.name in (? , ?);

我是否错过了告诉 JPA 它应该是一个 in clause

Dov*_*vmo 5

你很接近!您可以使用关键字In作为Name子句的限定符(如文档中所述)。您需要做的就是将您的查询修正为:

List<Student> findByGrpAndNameIn(String grp, Set<String> name);
Run Code Online (Sandbox Code Playgroud)

希望有帮助!