尝试使用 JDBC 驱动程序将 UUID 插入 Cassandra 1.2 时出现异常。这是代码:
UUID uuid = java.util.UUID.randomUUID();
PreparedStatement statement = c.prepareStatement("insert into tree (tree_id) values (?)");
statement.setObject(1, uuid);
statement.execute();
这是我得到的例外:
java.sql.SQLNonTransientException: encountered object of class: class java.util.UUID, but only 'String' is supported to map to the various VARCHAR types
at org.apache.cassandra.cql.jdbc.HandleObjects.makeBadMapping(HandleObjects.java:124)
at org.apache.cassandra.cql.jdbc.HandleObjects.makeBytes(HandleObjects.java:391)
at org.apache.cassandra.cql.jdbc.CassandraPreparedStatement.setObject(CassandraPreparedStatement.java:351)
at org.apache.cassandra.cql.jdbc.CassandraPreparedStatement.setObject(CassandraPreparedStatement.java:338)
at CassandraTest.main(CassandraTest.java:26)
这是我的架构:
CREATE TABLE browse.tree (tree_id UUID PRIMARY KEY, activation_time TIMESTAMP, tree_lock_id INT, sql_publication_id INT);
它认为我的 UUID 字段是 VARCHAR 有点奇怪。任何帮助将不胜感激。谢谢!