首页 文章

使用CassandraAdminOperations.createTable在Cassandra表中创建uuid类型字段

提问于
浏览
0

使用CassandraAdminOperations.createTable创建具有UUID类型字段的表时遇到问题 . 我使用类型uuid在表中定义了字段,但是当使用CassandraAdminOperations.createTable创建表时,该字段被创建为timeuuid . 有没有办法迫使该领域uuid而不是timeuuid?

这是课堂上的字段定义,

@PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private UUID id;

@Column(value = "url")
private String url;

但是当调用CassandraAdminOperations.createTable来创建表时,日志显示以下内容并且id字段被创建为timeuuid,

00:43:23.877 [localhost-startStop-1] DEBUG o.s.d.c.core.CassandraAdminTemplate - CREATE TABLE IF NOT EXISTS id_to_url_map(id timeuuid,url text,PRIMARY KEY(id));

谢谢!

1 回答

  • 2

    我有同样的问题 . 但经过一些调查,我发现你可以添加 @CassandraType 注释,并明确指定类 .

    import com.datastax.driver.core.DataType;
    
        @PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
        @CassandraType(type = DataType.Name.UUID)
        private UUID id;
    

相关问题