Java 尝试通过图形API获取OrientDB的ORecordBytes时发生ClassCastException
我尝试使用OrientDB存储图像/字节数据,并遵循本教程:(我选择了“使用ORecordBytes存储它”的方法) 使用以下代码存储数据似乎不会引起任何问题:Java 尝试通过图形API获取OrientDB的ORecordBytes时发生ClassCastException,java,orientdb,Java,Orientdb,我尝试使用OrientDB存储图像/字节数据,并遵循本教程:(我选择了“使用ORecordBytes存储它”的方法) 使用以下代码存储数据似乎不会引起任何问题: Vertex vertex = db.addVertex("class:items"); ... ORecordBytes imageRecord = new ORecordBytes(stream.toByteArray()); imageRecord.save(); vertex.setProperty
Vertex vertex = db.addVertex("class:items");
...
ORecordBytes imageRecord = new ORecordBytes(stream.toByteArray());
imageRecord.save();
vertex.setProperty("image", imageRecord);
...
db.commit();
但是,当我尝试像这样检索数据时:
ORecordBytes imageRecord = vertex.getProperty("image");
…我从上面的一行中得到:
Exception in thread "main" java.lang.ClassCastException: com.orientechnologies.orient.core.record.impl.ORecordBytes cannot be cast to com.orientechnologies.orient.core.record.impl.ODocument
at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.getElement(OrientBaseGraph.java:1145)
at com.tinkerpop.blueprints.impls.orient.OrientElement.getProperty(OrientElement.java:186)
at service.database.DAO.OrientDBGraphAPIItemDAO.vertexToItem(OrientDBGraphAPIItemDAO.java:154)
at service.database.DAO.OrientDBGraphAPIItemDAO.create(OrientDBGraphAPIItemDAO.java:68)
at testing.TestApplication.main(TestApplication.java:69)
我真的不知道我在哪一点上对OdoDocument进行了转换,但我不知道OrientDB的内部结构。由于本教程是为文档API编写的,我想知道这可能是原因吗?还是我只是缺少了一些其他内容?转换不是在您的代码中进行的,而是在OrientBaseGraph类中进行的,这是OrientDB内部cl屁股 应使用以下语法解决此问题:
vertex.getRecord().field("image");
无论如何,我认为这可能是一个问题,因此我建议您在OrientDB issue tracker中报告它。转换不是在您的代码中进行的,而是在OrientBaseGraph类中进行的,这是一个OrientDB内部类 应使用以下语法解决此问题:
vertex.getRecord().field("image");
无论如何,我认为这可能是一个问题,因此我建议您在OrientDB issue tracker中报告。您可以遵循Luigi的建议,但这已在1.7.8版中得到修复:
您可以按照Luigi的建议进行操作,但这已在1.7.8版中修复:
Thx的建议似乎有效。当然,这种方法必须将仅被断言为
com.tinkerpop.blueprints.vertex的顶点转换为com.tinkerpop.blueprints.impls.orient.OrientVertex
。非常脏,但作为临时解决办法(直到1.7.8)这是一个好主意:)。Thx的建议,似乎是可行的。当然,这种方式必须将只声明为com.tinkerpop.blueprints.vertex
的顶点强制转换为com.tinkerpop.blueprints.impls.orient.OrientVertex
。非常脏,但作为临时解决办法(直到1.7.8)这是一个好主意:)。在版本2 rc1上出现类似错误,更新为版本2 rc2,问题得到解决。在版本2 rc1上出现类似错误,更新为版本2 rc2,问题得到解决。