哪个数据类型在@rid的orient db中?

时间:2015-06-09 17:09:04

标签: java spring orientdb

我尝试使用java从orientdb获取所有数据。 我的代码是

    public static ArrayList<dbentity.DoctorEntity> viewAllDoctor(){
    graph = factory.getTx();
    ArrayList<dbentity.DoctorEntity> al=new ArrayList<dbentity.DoctorEntity>();
    for (Vertex v : graph.getVerticesOfClass("DoctorA")) {
        System.out.println(v.getProperty("@rid"));
        dbentity.DoctorEntity disent=new DoctorEntity(v.getProperty("@rid"), v.getProperty("NAME"),v.getProperty("specialization"));
        al.add(disent);
    }
    graph.shutdown();
    return al;
    }

我想将@rid添加到ArrayList但显示错误。我的问题与数据类型 我的DoctorEntity课程是。

public class DoctorEntity {
private String name;
private String specialization;
private String rid;

public DoctorEntity(Object rid, Object name,Object specialization){
    this.name=(String) name;
    this.specialization=(String) specialization;
    this.rid=(String) rid;
}

public String getName() {
    return name;
}

public String getSpecialization() {
    return specialization;
}
public String getRid() {
    return rid;
}}

错误显示是 exception:&#34; java.lang.ClassCastException&#34; 消息:&#34; com.tinkerpop.blueprints.impls.orient.OrientVertex无法强制转换为java.lang.String&#34;

1 个答案:

答案 0 :(得分:0)

您可以将顶点投射到 OrientVertex 并调用 getIdentity()。toString()。 请参阅here

for (Vertex v : graph.getVerticesOfClass("DoctorA")) {
    OrientVertex vertex = (OrientVertex) v;
    dbentity.DoctorEntity disent = new DoctorEntity(vertex.getIdentity().toString(), v.getProperty("NAME"), v.getProperty("specialization"));
    al.add(disent);
}