com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户”

Posted

技术标签:

【中文标题】com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户”【英文标题】:com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured table user" 【发布时间】:2017-12-28 05:18:42 【问题描述】:

我是 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 + '\'' +
                '';
    

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

【问题讨论】:

如果您可以共享完整的堆栈跟踪或异常,将会很有帮助。 【参考方案1】:

在键空间my_keyspace中创建user

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

【讨论】:

为什么@Override protected String getKeyspaceName() return KEYSPACE; 不起作用? @Alexandr 问题出在桌子上。

以上是关于com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户”的主要内容,如果未能解决你的问题,请参考以下文章

com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表用户”

com.datastax.driver.core.exceptions.InvalidQueryException:未配置的表 schema_keyspaces

java.lang.NoClassDefFoundError:无法初始化类 com.datastax.driver.core.Cluster

com.datastax.driver.core.TransportException: [/xx.xxx.x.xxx:9042] 无法连接

引起:com.datastax.driver.core.exceptions.InvalidQueryException:预计日期为 8 或 0 字节长 (13)

为啥 Spark Cassandra 连接器因 NoSuchMethodError: com.datastax.driver.core.TableMetadata.getIndexes()Ljava/