Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
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
–
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;
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.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.