Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

felix avatar image
felix asked Erick Ramirez edited

How can I use the IN() operator with the Java driver mapper?

I would like to do a select with two IN, but I always get:

com.datastax.oss.driver.api.core.type.codec.CodecNotFoundException: Codec not found for requested operation: [INT <-> java.util.List<java.lang.Integer>]

When I select for just a single column_two and column_three it works fine, and I also can run the query directly on the database without problems.

@Select(customWhereClause = "column_one = :columnOne AND column_two IN (:columnTwoList) AND column_three IN (:columnThree)")
MutinyMappedReactiveResultSet<NotificationRecord> findByIds(Integer columnOne, List<Integer> columnTwoList, List<Integer> columnThree);

SOLUTION: The Problem could be fixed by removing the parantheses from the query. Like:

@Select(customWhereClause = "column_one = :columnOne AND column_two IN :columnTwoList AND column_three IN :columnThree")
MutinyMappedReactiveResultSet<NotificationRecord> findByIds(Integer columnOne, List<Integer> columnTwoList, List<Integer> columnThree);
java driver
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez edited

I see that Alex Ott provided this answer to your question on Stack Overflow:

Binding declaration looks incorrect - instead of IN (:columnThree) try IN :columnThree. This happens because when you bind as IN (:columnThree) it expects that columnThree is one element inside the list, not the full list.
Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.