com.datastax.driver.core.exceptions.InvalidTypeException: Cannot parse '?' as a uuid value (unable to coerce '?' to version 1 UUID)

DataStax JIRA | Mike Schrag | 4 years ago
  1. 0
  2. 0
  3. 0

    Can't retrieve by UDT key from cassandra with datastax java driver

    Stack Overflow | 1 year ago | NullProgrammerException
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid value for CQL type frozen<example_keyspace.my_data_type>, expecting class com.datastax.driver.core.UDTValue but class me.example.Main$MyDataType provided
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Reported on [Stack Overflow|http://stackoverflow.com/questions/31373008/cant-retrieve-by-udt-key-from-cassandra-with-datastax-java-driver] Schema: {code} create keyspace example_keyspace; use example_keyspace; create type my_data_type (value text); create table my_classes (key frozen<my_data_type>, value frozen<my_data_type>, primary key (key)); {code} Java code: {code} package me.example; import com.datastax.driver.core.Cluster; import com.datastax.driver.mapping.Mapper; import com.datastax.driver.mapping.MappingManager; import com.datastax.driver.mapping.annotations.Frozen; import com.datastax.driver.mapping.annotations.PartitionKey; import com.datastax.driver.mapping.annotations.Table; import com.datastax.driver.mapping.annotations.UDT; public class Main { public static void main(String[] args) { try (Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1") .build()) { Mapper<MyClass> mapper = new MappingManager(cluster.newSession()) .mapper(MyClass.class); MyDataType value = new MyDataType(); value.setValue("theValue"); MyDataType key = new MyDataType(); key.setValue("theKey"); MyClass myClass = new MyClass(); myClass.setKey(key); myClass.setValue(value); mapper.save(myClass); MyClass toret = mapper.get(key); System.out.println(toret.getKey()); System.out.println(toret.getValue().getValue()); } } @Table(keyspace = "example_keyspace", name = "my_classes") public static class MyClass { @PartitionKey @Frozen private MyDataType key; @Frozen private MyDataType value; public MyDataType getKey() { return key; } public void setKey(MyDataType key) { this.key = key; } public MyDataType getValue() { return value; } public void setValue(MyDataType value) { this.value = value; } } @UDT(keyspace = "example_keyspace", name = "my_data_type") public static class MyDataType { private String value; public String getValue() { return value; } public void setValue(String value) { this.value = value; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((value == null) ? 0 : value.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof MyDataType)) { return false; } MyDataType other = (MyDataType) obj; if (value == null) { if (other.value != null) { return false; } } else if (!value.equals(other.value)) { return false; } return true; } } } {code} It fails with this exception: {code} Exception in thread "main" com.datastax.driver.core.exceptions.InvalidTypeException: Invalid value for CQL type frozen<example_keyspace.my_data_type>, expecting class com.datastax.driver.core.UDTValue but class me.example.Main$MyDataType provided at com.datastax.driver.core.DataType.serialize(DataType.java:619) at com.datastax.driver.mapping.Mapper.getQuery(Mapper.java:320) at com.datastax.driver.mapping.Mapper.get(Mapper.java:342) at me.example.Main.main(Main.java:31) {code} There is a workaround: {code} MappingManager manager = new MappingManager(cluster.newSession()); UDTMapper<MyDataType> myDataTypeMapper = manager.udtMapper(MyDataType.class); UDTValue keyAsUDTValue = myDataTypeMapper.toUDT(key); MyClass toret = mapper.get(keyAsUDTValue); {code}

    DataStax JIRA | 1 year ago | Olivier Michallat
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid value for CQL type frozen<example_keyspace.my_data_type>, expecting class com.datastax.driver.core.UDTValue but class me.example.Main$MyDataType provided
  6. 0

    Invalid serialised value error when reading a map of stringified json objects from Cassandra 1.2 using DataStax 1.0.5 java driver and Cassaforte

    Stack Overflow | 3 years ago | Anna Pawlicka
    com.datastax.driver.core.exceptions.InvalidTypeException: Invalid serialized value for type map&lt;text, text&gt; (String didn't validate.)

    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

      Cannot parse '?' as a uuid value (unable to coerce '?' to version 1 UUID)

      at com.datastax.driver.core.DataType.parse()
    2. DataStax Java Driver for Apache Cassandra - Core
      Insert.value
      1. com.datastax.driver.core.DataType.parse(DataType.java:412)
      2. com.datastax.driver.core.querybuilder.BuiltStatement.maybeAddRoutingKey(BuiltStatement.java:73)
      3. com.datastax.driver.core.querybuilder.Insert.value(Insert.java:81)
      3 frames