0

I got an enum (ClubRole) which got a method returning a collection of values from this enum. I trying to call this method from inside the query using SpEl.

 @Query("select m from ClubMember m " +
    "where m.student = :student " +
    "and m.role in :#{#role.getParents()}"
  )
  List<ClubMember> findByRoleWithInheritance(@Param("student") Student student, @Param("role") ClubRole role);

This passes the build, and the application runs but when this method's called I got ``No parameter binding found for name role!; nested exception is java.lang.IllegalArgumentException: No parameter binding found for name role!

I tried different ways but none worked. I would like to know if it's possible to use SpEl in this situation, and if so how ?

Warthy
  • 37
  • 8

1 Answers1

1

Looks like this is an issue in spring-data-jpa. I could see people discussing same issue on spring-blog. Not sure whether there is an open issue for this. You can try following as a workaround.

@Query("select m from ClubMember m " +
    "where m.student = :#{#student}" +
    "and m.role in :#{#role.getParents()}"
  )
  List<ClubMember> findByRoleWithInheritance(@Param("student") Student student, @Param("role") ClubRole role);

Or you can try with index access for second parameter like #{[1].getParents()}

this might help.

Nawnit Sen
  • 973
  • 2
  • 7
  • 14
  • If your issue is resolved can you please mark it as accepted? .It will help others as well. – Nawnit Sen Jul 27 '19 at 19:44
  • just did. However the solution is very specific to my problem so i don't know if it'll help others. The "error" if it's one is extremely odd – Warthy Jul 27 '19 at 19:49
  • Thanks!! your are not the first one to get this error though :) I'll open an issue for this – Nawnit Sen Jul 27 '19 at 19:51
  • 1
    Good call, i too found a lot of similar issue concerning IN clause with SpEL. This topic https://stackoverflow.com/questions/29127723/spring-data-jpa-query-with-spel-in-a-in-query talked about a issue but it's was supposedly fixed. – Warthy Jul 27 '19 at 19:59