我正在使用 spring JPA 在 MySql 数据库上进行选择操作
表格
select id, grp, name from student;
存储库方法
List<Student> findByGrpAndName(String grp, Set<String> name);
它正在 throw
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
最佳答案
你很接近!您可以使用关键字 In
作为 Name
子句的限定符(如 in the documentation 所述)。您需要做的就是将您的查询修改为:
List<Student> findByGrpAndNameIn(String grp, Set<String> name);
希望对您有所帮助!
关于java - 抛出操作数的子句中的 Spring JPA 应包含 1 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51227849/