无法从Cassandra数据库获取数据

时间:2015-06-09 04:52:36

标签: cassandra-2.0

你好,我是Cassandra数据库的新手。我正在使用Valchkau映射器驱动程序来存储和从数据库中获取Object。我在net上有一个与复合主键相关的例子。使用此示例,我可以将数据存储在数据库中,但无法使用映射器类检索它。 link which I followed

CompositeKey类:

public class CompositeKey {
private String name;
private int rank;

public CompositeKey(String name, int rank) {
    super();
    this.name = name;
    this.rank = rank;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getRank() {
    return rank;
}

public void setRank(int rank) {
    this.rank = rank;
}

@Override
public String toString() {
    return "CompositeKey [name=" + name + ", rank=" + rank + "]";
}

}

实体类:

import javax.persistence.EmbeddedId;
import javax.persistence.Table;

@Table(name = "entity")

public class Entity {

@EmbeddedId
private CompositeKey key;

private String email;

public Entity(CompositeKey key, String email) {
    super();
    this.key = key;
    this.email = email;
}

public CompositeKey getKey() {
    return key;
}

public void setKey(CompositeKey key) {
    this.key = key;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

@Override
public String toString() {
    return "Entity [key=" + key + ", email=" + email + "]";
}

}

我的主要课程是:

import java.util.List;

import com.cisco.cassandra.util.MapperCassandraSession;
import com.datastax.driver.core.Statement;
import com.datastax.driver.core.querybuilder.QueryBuilder;

public class Main {
    public static void main(String[] args) {

    Statement stmt = QueryBuilder.select().all().from("entity").where(QueryBuilder.eq("name", "Ram"));
    List<Entity> listEntity = MapperCassandraSession.getMappingSession().getByQuery(Entity.class, stmt);

    System.out.println(listEntity);
}

}

请尽快提供帮助。感谢

0 个答案:

没有答案