2016-04-23 91 views
0

我在尝试访问的关系文档时出现以下异常:OrientDB ClassCastException异常

java.lang.ClassCastException: com.orientechnologies.orient.core.id.ORecordId cannot be cast to com.orientechnologies.orient.core.record.impl.ODocument 

通过:

Collection<ODocument> field = myDoc.field("MY_FIELD_NAME"); 
     if(field != null) { 
      return field; 
     } else { 
      return Collections.emptySet(); 
     } 

奇怪的是happes并非总是如此,大部分时间它的工作原理像预期一样。

回答

0

根据字段包含的内容,您可以使用接口OIdentifiable而不是ODocument。 尝试使用:

Collection<OIdentifiable> field = myDoc.field("MY_FIELD_NAME"); 
if(field != null) { 
    return field; 
} else { 
    return Collections.emptySet(); 
} 
+0

该字段包含其他ODocuments,其一个典型的(双)定向关系的集合。 – kerner1000

+0

不幸的是,这并没有太大的帮助,因为我需要ODocument实例。有了OIdentifiable,你不能做很多事情。 – kerner1000

+0

你应该通过执行一个'identifiable.getRecord()'来取得记录。如果你有ORecordId或ODocument,这总是有效的。 – Lvca