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.
Try it without the brackets
Latest version of Spring Data JPA supports IN keyword which can be used to create the query like following: