com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户“ [英] com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table user"
问题描述
我是Cassandra的新手,这给了我很多问题.我下载了apache-Cassandra 3.11,使用的是Spring Boot 1.5.4.RELEASE.我做了一些研究,发现了源所在的位置说这可能是因为Spring数据使用了不同的Cassandra驱动程序核心版本?但是最新使用cql 3正确吗?我还制作了一个Java类配置文件.问题可能在这里.
I am new to Cassandra and this has been giving me issues. I downloaded apache-Cassandra 3.11 and I am using spring boot 1.5.4.RELEASE. I did some research and found a source where it says it may be because Spring data is using a different Cassandra driver core version? But the latest uses cql 3 correct? I also made a java class configuration file. The issue may be here.
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
This is the bean am trying to use
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 + '\'' +
'}';
}
}
如果您需要更多信息,请告诉我,我一生都无法找出问题所在.谢谢.
If you need more information, let me know, I cannot for the life of me figure out what is wrong. Thank you.
推荐答案
在密钥空间 my_keyspace
CREATE TABLE user(
id uuid PRIMARY KEY,
firstName text,
lastName text
);
这篇关于com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!