使用 POJO 时未配置的 columnfamily Cassandra 错误
unconfigured columnfamily Cassandra Error while Using POJO
我正在按照下面的 link 将 Person 对象插入到 Person table 驻留在 Cassandra 服务器上
http://docs.spring.io/spring-data/cassandra/docs/1.0.4.RELEASE/reference/html/cassandra.core.html
但我有 unconfigured columnfamily error
。我已经测试了几种方法来实现它。有些方法可以正常工作。这是结果。
1- 运行 正确
PreparedStatement statement = session.prepare("INSERT INTO \"tims\".\"Person\" (id, name, age) VALUES (?,?,?)");
int id=1234;
String name="Ahmet"+id;
int age=33;
BoundStatement bind = statement.bind(id,name,age);
session.executeAsync(bind);
2- 运行 正确
String cql = "insert into \"tims\".\"Person\" (id, name, age) values (2345, 'Ali-updated-2', 39)";
CassandraOperations cassandraOps = new CassandraTemplate(session);
cassandraOps.execute(cql);
3- 不 运行 正确地
CassandraOperations cassandraOps = new CassandraTemplate(session);
cassandraOps.insert(new Person(2345, "Ahmet-updated", 33));
这是 POJO CLASS
package com.ttech.tims.bipcamp.dao.cassandra;
import org.springframework.data.cassandra.mapping.Column;
import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;
@Table(value="Person")
public class Person {
@PrimaryKey(value="id")
@Column(value="id")
private int id;
@Column(value="name")
private String name;
@Column(value="age")
private int age;
public Person(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
我下载了以下API
的源码
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.0.6.RELEASE</version>
</dependency>
我发现以下方法 returns 行第一列的值
cassandraOps.queryForObject(s, Person.class)
有以下方法跟踪。
CqlTemplate-> processOne()
@SuppressWarnings("unchecked")
@Override
public <T> T processOne(ResultSet resultSet, Class<T> requiredType) throws DataAccessException {
if (resultSet == null) {
return null;
}
Row row = resultSet.one();
if (row == null) {
return null;
}
return (T) firstColumnToObject(row);
}
我用过其他两个样本:
Map map = cassandraOps.queryForMap(s);
System.out.println("id:"+map.get("id")+", name:"+map.get("name")+", age:"+map.get("age"));
Person person = cassandraOps.queryForObject(s, new RowMapper<Person>(){
@Override
public Person mapRow(Row row, int rowNum) throws DriverException {
return new Person(row.getInt(0), row.getString(1),row.getInt(2));
}
});
System.out.println("Person:"+person);
我找到了带有键空间的插入语句的实际解决方案。使用以下内容更新依赖项列表。
<properties>
<org.springframework.version>4.0.5.RELEASE</org.springframework.version>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
我正在按照下面的 link 将 Person 对象插入到 Person table 驻留在 Cassandra 服务器上 http://docs.spring.io/spring-data/cassandra/docs/1.0.4.RELEASE/reference/html/cassandra.core.html
但我有 unconfigured columnfamily error
。我已经测试了几种方法来实现它。有些方法可以正常工作。这是结果。
1- 运行 正确
PreparedStatement statement = session.prepare("INSERT INTO \"tims\".\"Person\" (id, name, age) VALUES (?,?,?)");
int id=1234;
String name="Ahmet"+id;
int age=33;
BoundStatement bind = statement.bind(id,name,age);
session.executeAsync(bind);
2- 运行 正确
String cql = "insert into \"tims\".\"Person\" (id, name, age) values (2345, 'Ali-updated-2', 39)";
CassandraOperations cassandraOps = new CassandraTemplate(session);
cassandraOps.execute(cql);
3- 不 运行 正确地
CassandraOperations cassandraOps = new CassandraTemplate(session);
cassandraOps.insert(new Person(2345, "Ahmet-updated", 33));
这是 POJO CLASS
package com.ttech.tims.bipcamp.dao.cassandra;
import org.springframework.data.cassandra.mapping.Column;
import org.springframework.data.cassandra.mapping.PrimaryKey;
import org.springframework.data.cassandra.mapping.Table;
@Table(value="Person")
public class Person {
@PrimaryKey(value="id")
@Column(value="id")
private int id;
@Column(value="name")
private String name;
@Column(value="age")
private int age;
public Person(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
我下载了以下API
的源码<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.0.6.RELEASE</version>
</dependency>
我发现以下方法 returns 行第一列的值
cassandraOps.queryForObject(s, Person.class)
有以下方法跟踪。
CqlTemplate-> processOne()
@SuppressWarnings("unchecked")
@Override
public <T> T processOne(ResultSet resultSet, Class<T> requiredType) throws DataAccessException {
if (resultSet == null) {
return null;
}
Row row = resultSet.one();
if (row == null) {
return null;
}
return (T) firstColumnToObject(row);
}
我用过其他两个样本:
Map map = cassandraOps.queryForMap(s);
System.out.println("id:"+map.get("id")+", name:"+map.get("name")+", age:"+map.get("age"));
Person person = cassandraOps.queryForObject(s, new RowMapper<Person>(){
@Override
public Person mapRow(Row row, int rowNum) throws DriverException {
return new Person(row.getInt(0), row.getString(1),row.getInt(2));
}
});
System.out.println("Person:"+person);
我找到了带有键空间的插入语句的实际解决方案。使用以下内容更新依赖项列表。
<properties>
<org.springframework.version>4.0.5.RELEASE</org.springframework.version>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>