9

I'm using Spring Data Cassandra.I'm getting exception when i pass multiple parameters to the repository method. Can anyone help how to pass multiple parameters to append and use where clause.

My Repo method:

@Query("select site_name,month_gen from mykeyspace.dgr_item where type='Site' and name = ?0 and dgr_date in (:list)")
public List<Object> findGen(String siteName, @Param("list") List<Date> listt);

Exception:

Caused by: java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all!
at org.springframework.util.Assert.isTrue(Assert.java:68)
at org.springframework.data.repository.query.Parameters.assertEitherAllParamAnnotatedOrNone(Parameters.java:294)
at org.springframework.data.repository.query.Parameters.<init>(Parameters.java:91)
at org.springframework.data.cassandra.repository.query.CassandraParameters.<init>(CassandraParameters.java:45)
at org.springframework.data.cassandra.repository.query.CassandraQueryMethod.createParameters(CassandraQueryMethod.java:131)
at org.springframework.data.cassandra.repository.query.CassandraQueryMethod.createParameters(CassandraQueryMethod.java:45)
at org.springframework.data.repository.query.QueryMethod.<init>(QueryMethod.java:75)
at org.springframework.data.cassandra.repository.query.CassandraQueryMethod.<init>(CassandraQueryMethod.java:64)
at org.springframework.data.cassandra.repository.support.CassandraRepositoryFactory$CassandraQueryLookupStrategy.resolveQuery(CassandraRepositoryFactory.java:152)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:436)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263)
at org.springframework.data.cassandra.repository.support.CassandraRepositoryFactoryBean.afterPropertiesSet(CassandraRepositoryFactoryBean.java:76)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 41 common frames omitted
sreedhar
  • 296
  • 1
  • 5
  • 15
  • 2
    Caused by: java.lang.IllegalArgumentException: Either use Param annotation on all parameters except Pageable and Sort typed once, or none at all! states that all the parameters should have Param annotation your first argument is not having it. – pshirishreddy Apr 19 '17 at 07:45
  • I added @Param for first parameter also and problem solved.Thank you. – sreedhar Apr 19 '17 at 07:56
  • converted it to answer to accept it. – pshirishreddy Apr 19 '17 at 11:52

4 Answers4

7

Caused by: java.lang.IllegalArgumentException: Either use Param annotation on all parameters except Pageable and Sort typed once, or none at all! states that all the parameters should have Param annotation your first argument is not having it

pshirishreddy
  • 746
  • 6
  • 20
5

This can also happen if you use PageRequest in the repository as well.

you should use Pageable with below import,

import org.springframework.data.domain.Pageable;
tk_
  • 16,415
  • 8
  • 80
  • 90
0

I had the same problem I had added space between : and expression value.

@Query ("SELECT yoga FROM Yoga yoga WHERE yoga.status =: status AND yoga.category =: category ORDER BY yoga.priorityOrder DESC")
List<YogaMaster> getVideosOfACategory(@Param("status")int status, @Param("category") String category, Pageable pageable);

Then I changed to

@Query ("SELECT yoga FROM YogaMaster yoga WHERE yoga.status = :status AND yoga.category = :category ORDER BY yoga.priorityOrder DESC")
List<YogaMaster> getTop4VideosOfACategory(@Param("status")int status, @Param("category") String category, Pageable pageable);

and it worked.

the difference was =: category(wrong) and = :category(right), check the spacing.

This could be due to one more issue if your use PageRequest instead of Pageable.

Rakesh Yadav
  • 1,966
  • 2
  • 21
  • 35
0

I encountered the same exception when I accidentally imported the wrong Pageable class and googling led me here.

Error404
  • 719
  • 9
  • 30