[英]SPRING|Java - Use IN clause with SpEl in query
I got an enum (ClubRole) which got a method returning a collection of values from this enum. 我有一个枚举(ClubRole),它有一个从该枚举返回值集合的方法。 I trying to call this method from inside the query using SpEl.
我试图使用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!
嵌套异常是java.lang.IllegalArgumentException:未找到名称角色的参数绑定!
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 ?
我想知道在这种情况下是否可以使用SpEl,如果可以,怎么办?
Looks like this is an issue in spring-data-jpa. 看来这是spring-data-jpa中的问题。 I could see people discussing same issue on spring-blog.
我可以看到人们在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()}
或者,您可以尝试对第二个参数(如
#{[1].getParents()}
进行索引访问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.