gpt4 book ai didi

java - com.datastax.driver.core.exceptions.InvalidQueryException : unconfigured table user"

转载 作者:行者123 更新时间:2023-11-30 02:27:34 25 4
gpt4 key购买 nike

我是 Cassandra 新手,这一直给我带来问题。我下载了 apache-Cassandra 3.11,我使用的是 spring boot 1.5.4.RELEASE。我做了一些研究,发现了 source它在哪里说这可能是因为 Spring 数据使用不同的 Cassandra 驱动程序核心版本?但最新使用的cql 3正确吗?我还制作了一个java类配置文件。问题可能出在这里。

import org.springframework.cassandra.config.CassandraCqlClusterFactoryBean;
import org.springframework.cassandra.config.DataCenterReplication;
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableCassandraRepositories
public class CassandraConfig extends AbstractCassandraConfiguration{
private static final String KEYSPACE = "my_keyspace";

@Bean
@Override
public CassandraCqlClusterFactoryBean cluster() {
CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean();
bean.setKeyspaceCreations(getKeyspaceCreations());
return bean;
}

/**
* if it dont exist , create it
* @return
*/
@Override
public SchemaAction getSchemaAction() {
return SchemaAction.CREATE_IF_NOT_EXISTS;
}

@Override
protected String getKeyspaceName() {
return KEYSPACE;
}

@Override
public String[] getEntityBasePackages() {
return new String[]{"com.cassandra"};
}

protected List<CreateKeyspaceSpecification> getKeyspaceCreations() {
List<CreateKeyspaceSpecification> createKeyspaceSpecifications = new ArrayList<>();
createKeyspaceSpecifications.add(getKeySpaceSpecification());
return createKeyspaceSpecifications;
}

// Below method creates "my_keyspace" if it doesnt exist.
private CreateKeyspaceSpecification getKeySpaceSpecification() {
CreateKeyspaceSpecification pandaCoopKeyspace = new CreateKeyspaceSpecification();
DataCenterReplication dcr = new DataCenterReplication("dc1", 3L);
pandaCoopKeyspace.name(KEYSPACE);
pandaCoopKeyspace.ifNotExists(true).createKeyspace().withNetworkReplication(dcr);
return pandaCoopKeyspace;
}


@Override
public String getContactPoints() {
return "localhost";
}
}

这是我尝试使用的bean

import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;

import java.util.UUID;

@Table("user")
public class User {

@PrimaryKey
private UUID id;

private String firstName;

private String lastName;

public User() {
super();
}

public User(UUID id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}

public User(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

@Override
public String toString() {
return "User{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
'}';
}
}

如果您需要更多信息,请告诉我,我一生都无法弄清楚出了什么问题。谢谢。

最佳答案

在键空间my_keyspace中创建user

CREATE TABLE user(
id uuid PRIMARY KEY,
firstName text,
lastName text
);

关于java - com.datastax.driver.core.exceptions.InvalidQueryException : unconfigured table user",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45249787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com