Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data JPA repositories: IN-clause in derived query not working

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);
}

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)

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.

like image 829
jensengar Avatar asked Oct 31 '14 14:10

jensengar


1 Answers

Try it without the brackets

@Query("select u from User u where u.id in :ids")
like image 170
Predrag Maric Avatar answered Sep 27 '22 19:09

Predrag Maric