Spring Data JPA存储库:派生查询中的IN子句不起作用 [英] Spring Data JPA repositories: IN-clause in derived query not working
本文介绍了Spring Data JPA存储库:派生查询中的IN子句不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的存储库:
I have a repository that looks like this:
public interface UserRepository extends JpaRepository<User, Long>
{
User findByEmailIgnoreCase(String email);
@Query("select u from User u where u.id in (:ids)")
Set<User> getByIdInSet(@Param("ids") Set<Long> ids);
}
当我打电话给 getByIdInSet
我收到以下错误:
When I call getByIdInSet
I get the following error:
Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class org.eclipse.persistence.indirection.IndirectSet for parameter ids with expected type of class java.lang.Long from query string select u from User u where u.id in (:ids).
at org.eclipse.persistence.internal.jpa.QueryImpl.setParameterInternal(QueryImpl.java:933)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.setParameter(EJBQueryImpl.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
显然我不知道是什么意思,因为我尝试更改各种数据类型并仍然得到相同的错误。我传递的id组只包含一个id。请指出正确的方向。
Apparently I don't know what means because I have tried changing all sorts of data types and still get the same error. The set of ids I am passing contains just one id. Please point me in the right direction.
推荐答案
尝试不带括号
@Query("select u from User u where u.id in :ids")
这篇关于Spring Data JPA存储库:派生查询中的IN子句不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文