2

I'm using spring JPA for select operation on MySql Database

Table

select id, grp, name from student;

Repository method

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

And it's throwing

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)

I tried to debug the hibernet code to see the query getting created. And query has syntax error.

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

It should be student0_.name in (? , ?);

Am I missing something to tell JPA it should be an in clause

Pasupathi Rajamanickam
  • 1,982
  • 1
  • 24
  • 48
  • What is the implementation of the method findByGrpAndName? – javamusings Jul 08 '18 at 01:58
  • 1
    In JPA, repository functions don't need the implementation. It follows some naming convention to detect what those functions are supposed to return. Further read: https://stackoverflow.com/questions/40330369/spring-data-jpa-underlying-mechanism-without-implementation – Nazar-E-Bukhari Jul 08 '18 at 04:29

1 Answers1

5

You're close! You can use the keyword In as a qualifier to the Name clause (as described in the documentation). All you need to do is fix your query to be:

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

Hope that helps!

Dovmo
  • 8,121
  • 3
  • 30
  • 44