Kanhaiya Choudhary
Kanhaiya Choudhary

Reputation: 516

How to use IN operator in where clause of SpringBoot Cassandra

I am trying to run following query from SpringBoot repository

@Query("select * from c where id1 =?0 and id2 =?1 and id3 =?2 and c1 =?3 and year in :year and month in :month and day in :day and hour in :hour and minute in :minute"
public List<Counter> findCWithinRangeIn(
    @Param("id1") String id1,
    @Param("id2") String id2,
    @Param("id3") String id3,
    @Param("c1") String c1,
    @Param("year") List<Integer> year,
    @Param("month") List<Integer> month,
    @Param("day") List<Integer> day, 
    @Param("hour") List<Integer> hour,
    @Param("minute") List<Integer> minute);

But always hitting error : Invalid amount of bind variables.

Please suggest on how to proceed further.

Note: I did follow Spring CrudRepository findByInventoryIds(List<Long> inventoryIdList) - equivalent to IN clause but it did not work for me.

I want to execute something like:

select * from c
where id1 ="xyz" and 
      id2 ="abc" and 
      id3 ="pqr" and 
      c1 = "Sample" and
      year IN (2016,2017) and
      month IN (9,10,11) and
      day IN (19,20,24) and
      hour IN (23, 13) and
      minute IN (50, 51, 53)

Upvotes: 4

Views: 1146

Answers (1)

bilak
bilak

Reputation: 4954

If you don't need to specify custom query this could work for you (based on method name)

public List<Counter> findAllById1AndId2AndId3AndC1AndYearInAndMonthInAndDayInAndHourInAndMinuteIn(String id1, STring id2, String id3, String c1, List<Long> years, List<Long> months, List<Long> days, List<Long> hours, List<Long> minutes)

note: in your Counter entity the field's names must match the names of attribute names specified in method name.

Upvotes: 1

Related Questions