@rid 的 orient db 中的哪种数据类型?
which data type in orient db for @rid?
我尝试使用 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 class 是。
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 cannot be cast to 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 从 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 class 是。
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 cannot be cast to 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);
}