1

我的代码:

public class InsertSuperColumn {

    private static StringSerializer stringSerializer = StringSerializer.get();

    public static void main(String[] args) throws Exception {

        Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");

        Keyspace keyspaceOperator = HFactory.createKeyspace("Keyspace1", cluster);

        try {
            Mutator<String> mutator = HFactory.createMutator(keyspaceOperator, stringSerializer);
            mutator.insert("billing", "Super1", HFactory.createSuperColumn("jsmith", 
                    Arrays.asList(HFactory.createStringColumn("first", "John")), 
                    stringSerializer, stringSerializer, stringSerializer));

            SuperColumnQuery<String, String, String, String> superColumnQuery = 
                HFactory.createSuperColumnQuery(keyspaceOperator, stringSerializer, stringSerializer, 
                        stringSerializer, stringSerializer);
            superColumnQuery.setColumnFamily("Super1").setKey("billing").setSuperName("jsmith");

            QueryResult<HSuperColumn<String, String, String>> result = superColumnQuery.execute();

            System.out.println("Read HSuperColumn from cassandra: " + result.get());            
            System.out.println("Verify on CLI with:  get Keyspace1.Super1['billing']['jsmith'] ");

        } catch (HectorException e) {
            e.printStackTrace();
        } 
        cluster.getConnectionManager().shutdown();  

    }
}

我收到此错误:

Exception in thread "main" me.prettyprint.hector.api.exceptions.HInvalidRequestException: 
InvalidRequestException(why:Keyspace names must be case-insensitively unique ("new2" conflicts with "new2"))
4

1 回答 1

1

问题是您正在创建将多次存储超级列的键空间列族。你不能这样做,键空间列族必须唯一命名。这就是异常告诉你的:

why:Keyspace names must be case-insensitively unique 
("new2" conflicts with "new2")

因此,就您的代码而言,您可以正确创建列。尝试使用 Cassandra CLI 进行验证。

于 2013-05-15T09:09:30.327 回答