我尝试使用 OrientDB 来存储图像/字节数据并按照本教程进行操作:Store it with ORecordBytes (我选择了“使用 ORecordBytes 存储”方法)。
使用以下代码存储数据似乎不会造成任何问题:
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)
我真的不知道我在什么时候转换到 ODocument,但我不知道 OrientDB 的内部结构。由于本教程是为 Document API 编写的,我想知道这是否是原因所在?还是我只是缺少其他东西?
最佳答案
您可以按照 Luigi 的建议进行操作,但这已在 1.7.8 版本中修复:
关于java - 尝试通过 Graph API 使用 OrientDB 获取 ORecordBytes 时发生 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25068645/