com.datastax.driver.core.exceptions.InvalidTypeException: Column phones is of type 'org.apache.cassandra.db.marshal.FrozenType(org.apache.cassandra.db.marshal.ListType(org.apache.cassandra.db.marshal.UserType(complex,70686f6e65,616c696173:org.apache.cassandra.db.marshal.UTF8Type,6e756d626572:org.apache.cassandra.db.marshal.UTF8Type)))', cannot set to a list

DataStax JIRA | Nathan Scully | 2 years ago
  1. 0

    I am receiving an InvalidTypeException when attempting to set a collection on a UDT. I am copying the example from the Datastax site: [http://www.datastax.com/documentation/developer/java-driver/2.1/java-driver/reference/udtApi.html] Setup: {code:java} session.execute("CREATE TYPE complex.phone (" + " alias text," + " number text);" ); session.execute("CREATE TYPE complex.address (" + " street text," + " zip_code int," + " phones list<frozen<phone>>);" // NOTE: In the example this is 'phones list<phone>' - but I receive the following error if I don't set this to frozen: InvalidQueryException: Non-frozen collections are not allowed inside collections: list<phone> ); session.execute("CREATE TABLE complex.users (" + " id uuid PRIMARY KEY," + " name text," + " addresses frozen <address>);"); {code} And then running the following as a test: {code:java} PreparedStatement insertUserPreparedStatement = session.prepare("INSERT INTO complex.users (id, name, addresses) VALUES (?, ?, ?);"); PreparedStatement selectUserPreparedStatement = session.prepare("SELECT * FROM complex.users WHERE id = ?;"); UserType addressUDT = session.getCluster().getMetadata().getKeyspace("complex").getUserType("address"); UserType phoneUDT = session.getCluster().getMetadata().getKeyspace("complex").getUserType("phone"); UDTValue phone1 = phoneUDT.newValue() .setString("alias", "home") .setString("number", "1-707-555-1234"); UDTValue phone2 = phoneUDT.newValue() .setString("alias", "work") .setString("number", "1-800-555-9876"); UDTValue address = addressUDT.newValue() .setString("street", "123 Arnold Drive") .setInt("zip_code", 95476) .setList("phones", ImmutableList.of(phone1, phone2)); // ERROR THROWN HERE Map<String, UDTValue> addresses = new HashMap<String, UDTValue>(); addresses.put("Work", address); UUID userId = UUID.fromString("fbdf82ed-0063-4796-9c7c-a3d4f47b4b25"); session.execute(insertUserPreparedStatement.bind(userId, "G. Binary", addresses)); {code} This throws the error: {code:java} Exception in thread "main" com.datastax.driver.core.exceptions.InvalidTypeException: Column phones is of type 'org.apache.cassandra.db.marshal.FrozenType(org.apache.cassandra.db.marshal.ListType(org.apache.cassandra.db.marshal.UserType(complex,70686f6e65,616c696173:org.apache.cassandra.db.marshal.UTF8Type,6e756d626572:org.apache.cassandra.db.marshal.UTF8Type)))', cannot set to a list at com.datastax.driver.core.AbstractData.setList(AbstractData.java:277) at com.datastax.driver.core.AbstractData.setList(AbstractData.java:297) at DatastaxUDTExample.loadUsers(DatastaxUDTExample.java:92) at DatastaxUDTExample.main(DatastaxUDTExample.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) {code}

    DataStax JIRA | 2 years ago | Nathan Scully
    com.datastax.driver.core.exceptions.InvalidTypeException: Column phones is of type 'org.apache.cassandra.db.marshal.FrozenType(org.apache.cassandra.db.marshal.ListType(org.apache.cassandra.db.marshal.UserType(complex,70686f6e65,616c696173:org.apache.cassandra.db.marshal.UTF8Type,6e756d626572:org.apache.cassandra.db.marshal.UTF8Type)))', cannot set to a list
  2. 0

    I am receiving an InvalidTypeException when attempting to set a collection on a UDT. I am copying the example from the Datastax site: [http://www.datastax.com/documentation/developer/java-driver/2.1/java-driver/reference/udtApi.html] Setup: {code:java} session.execute("CREATE TYPE complex.phone (" + " alias text," + " number text);" ); session.execute("CREATE TYPE complex.address (" + " street text," + " zip_code int," + " phones list<frozen<phone>>);" // NOTE: In the example this is 'phones list<phone>' - but I receive the following error if I don't set this to frozen: InvalidQueryException: Non-frozen collections are not allowed inside collections: list<phone> ); session.execute("CREATE TABLE complex.users (" + " id uuid PRIMARY KEY," + " name text," + " addresses frozen <address>);"); {code} And then running the following as a test: {code:java} PreparedStatement insertUserPreparedStatement = session.prepare("INSERT INTO complex.users (id, name, addresses) VALUES (?, ?, ?);"); PreparedStatement selectUserPreparedStatement = session.prepare("SELECT * FROM complex.users WHERE id = ?;"); UserType addressUDT = session.getCluster().getMetadata().getKeyspace("complex").getUserType("address"); UserType phoneUDT = session.getCluster().getMetadata().getKeyspace("complex").getUserType("phone"); UDTValue phone1 = phoneUDT.newValue() .setString("alias", "home") .setString("number", "1-707-555-1234"); UDTValue phone2 = phoneUDT.newValue() .setString("alias", "work") .setString("number", "1-800-555-9876"); UDTValue address = addressUDT.newValue() .setString("street", "123 Arnold Drive") .setInt("zip_code", 95476) .setList("phones", ImmutableList.of(phone1, phone2)); // ERROR THROWN HERE Map<String, UDTValue> addresses = new HashMap<String, UDTValue>(); addresses.put("Work", address); UUID userId = UUID.fromString("fbdf82ed-0063-4796-9c7c-a3d4f47b4b25"); session.execute(insertUserPreparedStatement.bind(userId, "G. Binary", addresses)); {code} This throws the error: {code:java} Exception in thread "main" com.datastax.driver.core.exceptions.InvalidTypeException: Column phones is of type 'org.apache.cassandra.db.marshal.FrozenType(org.apache.cassandra.db.marshal.ListType(org.apache.cassandra.db.marshal.UserType(complex,70686f6e65,616c696173:org.apache.cassandra.db.marshal.UTF8Type,6e756d626572:org.apache.cassandra.db.marshal.UTF8Type)))', cannot set to a list at com.datastax.driver.core.AbstractData.setList(AbstractData.java:277) at com.datastax.driver.core.AbstractData.setList(AbstractData.java:297) at DatastaxUDTExample.loadUsers(DatastaxUDTExample.java:92) at DatastaxUDTExample.main(DatastaxUDTExample.java:57) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) {code}

    DataStax JIRA | 2 years ago | Nathan Scully
    com.datastax.driver.core.exceptions.InvalidTypeException: Column phones is of type 'org.apache.cassandra.db.marshal.FrozenType(org.apache.cassandra.db.marshal.ListType(org.apache.cassandra.db.marshal.UserType(complex,70686f6e65,616c696173:org.apache.cassandra.db.marshal.UTF8Type,6e756d626572:org.apache.cassandra.db.marshal.UTF8Type)))', cannot set to a list
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 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
  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

    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

      Column phones is of type 'org.apache.cassandra.db.marshal.FrozenType(org.apache.cassandra.db.marshal.ListType(org.apache.cassandra.db.marshal.UserType(complex,70686f6e65,616c696173:org.apache.cassandra.db.marshal.UTF8Type,6e756d626572:org.apache.cassandra.db.marshal.UTF8Type)))', cannot set to a list

      at com.datastax.driver.core.AbstractData.setList()
    2. DataStax Java Driver for Apache Cassandra - Core
      AbstractData.setList
      1. com.datastax.driver.core.AbstractData.setList(AbstractData.java:277)
      2. com.datastax.driver.core.AbstractData.setList(AbstractData.java:297)
      2 frames
    3. Unknown
      DatastaxUDTExample.main
      1. DatastaxUDTExample.loadUsers(DatastaxUDTExample.java:92)
      2. DatastaxUDTExample.main(DatastaxUDTExample.java:57)
      2 frames
    4. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:483)
      4 frames
    5. IDEA
      AppMain.main
      1. com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
      1 frame