I'm trying to save java.util.UUID
to Cassandra column of type timeuuid
. For example, that is a default spring-data-cassandra mapping: http://docs.spring.io/spring-data/cassandra/docs/current/reference/html/#mapping-conversion .
Value of UUID is generated by java.util.UUID#randomUUID()
I get an exception:
"com.datastax.driver.core.exceptions.InvalidQueryException: Invalid version for TimeUUID type"
Studying code at https://svn.apache.org/repos/asf/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java reveals the reason:
@Override
public void validate(byte[] bytes)
{
if (bytes.length != 16 && bytes.length != 0)
throw new MarshalException(String.format("TimeUUID should be 16 or 0 bytes (%d)", bytes.length));
// version is bits 4-7 of byte 6.
if (bytes.length > 0)
if ((bytes[6] & 0xf0) != 0x10)
throw new MarshalException("Invalid version for TimeUUID type.");
}