【发布时间】:2018-12-16 02:13:58
【问题描述】:
我正在使用 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)
我尝试调试休眠代码以查看创建的查询。并且查询有语法错误。
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
【问题讨论】:
-
findByGrpAndName方法的实现是什么?
-
在 JPA 中,存储库函数不需要实现。它遵循一些命名约定来检测这些函数应该返回什么。进一步阅读:stackoverflow.com/questions/40330369/…
标签: java mysql hibernate spring-boot spring-data-jpa