com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 0, column is a set but class java.lang.String provided

DataStax JIRA | Kairat Beq | 2 years ago
  1. 0

    *_Final fix:_* We're going to forbid bind markers in query builder methods that add a single element: {{update("foo").with(add("s", bindMarker())).where(eq("k", 1));}} The reason is that this would generate {{UPDATE foo SET s = s + {?} WHERE k = 1}}, which gets rejected by Cassandra (you can't bind an element inside a collection). So attempting to do this will throw an exception, the workaround is the one I mentioned in the comments: use `addAll` and then bind a singleton collection. This also applies to list append/prepend. ----- *_Initial issue description:_* With a table definition {code:java} create table user ( id uuid, addr_set set<text>, primary key ( id ) ); {code} Updating as {code:java} Update.Where u = QueryBuilder.update( "ks", "user" ) .with( QueryBuilder.add( "addr_set", bindMarker() ) ) .where( QueryBuilder.eq( "id", UUID.fromString( "valid uuid" ) ) ); PreparedStatement ps = session.prepare( u ); ResultSet resultSet = session.execute( ps.bind( "my address" ) ); {code} throws an exception {code:java} com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 0, column is a set but class java.lang.String provided at com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:169) at com.datastax.driver.core.DefaultPreparedStatement.bind(DefaultPreparedStatement.java:103) {code} Executing without preparing works fine.

    DataStax JIRA | 2 years ago | Kairat Beq
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 0, column is a set but class java.lang.String provided
  2. 0

    *_Final fix:_* We're going to forbid bind markers in query builder methods that add a single element: {{update("foo").with(add("s", bindMarker())).where(eq("k", 1));}} The reason is that this would generate {{UPDATE foo SET s = s + {?} WHERE k = 1}}, which gets rejected by Cassandra (you can't bind an element inside a collection). So attempting to do this will throw an exception, the workaround is the one I mentioned in the comments: use `addAll` and then bind a singleton collection. This also applies to list append/prepend. ----- *_Initial issue description:_* With a table definition {code:java} create table user ( id uuid, addr_set set<text>, primary key ( id ) ); {code} Updating as {code:java} Update.Where u = QueryBuilder.update( "ks", "user" ) .with( QueryBuilder.add( "addr_set", bindMarker() ) ) .where( QueryBuilder.eq( "id", UUID.fromString( "valid uuid" ) ) ); PreparedStatement ps = session.prepare( u ); ResultSet resultSet = session.execute( ps.bind( "my address" ) ); {code} throws an exception {code:java} com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 0, column is a set but class java.lang.String provided at com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:169) at com.datastax.driver.core.DefaultPreparedStatement.bind(DefaultPreparedStatement.java:103) {code} Executing without preparing works fine.

    DataStax JIRA | 2 years ago | Kairat Beq
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 0, column is a set but class java.lang.String provided
  3. 0

    InvalidTypeException: Invalid type for value..

    GitHub | 1 year ago | 13o6
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 1 of CQL type varchar, expecting class java.lang.String but class java.nio.HeapByteBuffer provided
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Where clause does not work for Date type

    GitHub | 2 years ago | vsubrama001
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid type for value 0 of CQL type timestamp, expecting class java.util.Date but class java.lang.String provided

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. com.datastax.driver.core.exceptions.InvalidTypeException

      Invalid type for value 0, column is a set but class java.lang.String provided

      at com.datastax.driver.core.BoundStatement.bind()
    2. DataStax Java Driver for Apache Cassandra - Core
      DefaultPreparedStatement.bind
      1. com.datastax.driver.core.BoundStatement.bind(BoundStatement.java:169)
      2. com.datastax.driver.core.DefaultPreparedStatement.bind(DefaultPreparedStatement.java:103)
      2 frames