首页 > 解决方案 > 为什么 Spring Cassandra 不将 @Table 中设置的值与 Scala 一起使用?

问题描述

我有以下代码...

@Table(keyspace = "ks", name="otherThing" )
class Thing extends Serializable{
  ...
}

然而当我跑...

repo.findAll()

我收到一个错误,看起来好像没有使用我提供的值...

询问; CQL [SELECT * FROM Thing;]; 未配置的表事物

我希望

Select * from ks.otherThing;

我错过了什么?

更新

我尝试转换为以下 Pojo

import com.datastax.driver.mapping.annotations.Table;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
@Table( keyspace="ks", name="otherThing" )
public class Thing implements Serializable {
    ...
}

我的回购很简单......

import org.springframework.stereotype.Repository;

@Repository
public interface ThingRepository extends CassandraRepository<Thing, ThingId> { }

thingRepo.findAll();

给...

询问; CQL [SELECT * FROM 事物;]; 未配置的表事物

标签: springscalacassandra

解决方案


所以我犯的错误是试图通过使用我公司的 spring autoconfig 设置的连接来做到这一点。这使我可以通过application.properties. 我注意到之前在那里声明了键空间,所以我回去将我的域对象更改为...

import org.springframework.data.cassandra.core.mapping.Table

@Table("otherThing" )
class Thing extends Serializable{
  ...
}

现在它正在工作。留下这个答案以防其他人感到困惑。


推荐阅读