gpt4 book ai didi

java - @rid 东方数据库中的哪种数据类型?

转载 作者:太空宇宙 更新时间:2023-11-04 13:46:53 27 4
gpt4 key购买 nike

我尝试使用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;
}}

错误显示为异常:“java.lang.ClassCastException”消息:“com.tinkerpop.blueprints.impls.orient.OrientVertex 无法转换为 java.lang.String”

最佳答案

您可以将 Vertex 转换为 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);
}

关于java - @rid 东方数据库中的哪种数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30738566/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com