gpt4 book ai didi

java - Spring Data JPA 存储库 : IN-clause in derived query not working

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:44:31 25 4
gpt4 key购买 nike

我有一个看起来像这样的存储库:

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 时,出现以下错误:

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。请指出正确的方向。

最佳答案

不加括号试试

@Query("select u from User u where u.id in :ids")

关于java - Spring Data JPA 存储库 : IN-clause in derived query not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26677310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com