简体   繁体   English

使用Java在ArangoDB中查询Edge会引发Gson异常

[英]Query for Edges in ArangoDB with Java throws Gson exception

I'm new to ArangoDB and trying to do a few very basic queries. 我是ArangoDB的新手,正在尝试做一些非常基本的查询。 I was successful to add vertices and edges, but the query retrieving edges always throws an exception. 我成功添加了顶点和边,但是检索边的查询始终会引发异常。 I tried a few different queries from the (very minimalistic) documentation and it always throws the same. 我从(非常简约的)文档中尝试了一些不同的查询,并且总是抛出相同的查询。 Here is one of the queries: 这是查询之一:

CursorEntity<BaseDocument> r = arangoDriver.graphGetEdges("MyGraph", BaseDocument.class, "Person/1");
while (r.iterator().hasNext()){
    BaseDocument d = r.iterator().next();
    System.out.println(d.getDocumentHandle());
}

Or this one with the same exception: 或与此相同的例外:

String query = "for i in GRAPH_EDGES(@graphName, @vertexId, {direction: 'outbound', edgeCollectionRestriction: 'Friends'}) return i";
    Map<String, Object> bindVars = new MapBuilder().put("graphName", "MyGraph").put("vertexId", "Person/1").get();
    CursorEntity<PlainEdgeEntity> result;
    try {
        result = arangoDriver.executeQuery(query, bindVars, PlainEdgeEntity.class ,true, 10);

And here the exception: 这里是例外:

Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176)
at com.google.gson.Gson.fromJson(Gson.java:803)
at com.google.gson.Gson.fromJson(Gson.java:868)
at com.google.gson.Gson$1.deserialize(Gson.java:126)
at com.arangodb.entity.EntityDeserializers$CursorEntityDeserializer.deserialize(EntityDeserializers.java:519)
at com.arangodb.entity.EntityDeserializers$CursorEntityDeserializer.deserialize(EntityDeserializers.java:488)
at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
at com.google.gson.Gson.fromJson(Gson.java:803)
at com.google.gson.Gson.fromJson(Gson.java:768)
at com.google.gson.Gson.fromJson(Gson.java:717)
at com.arangodb.entity.EntityFactory.createEntity(EntityFactory.java:109)
at com.arangodb.BaseArangoDriver.createEntityImpl(BaseArangoDriver.java:270)
at com.arangodb.BaseArangoDriver.createEntity(BaseArangoDriver.java:181)
at com.arangodb.BaseArangoDriver.createEntity(BaseArangoDriver.java:219)
at com.arangodb.impl.InternalCursorDriverImpl.executeQuery(InternalCursorDriverImpl.java:78)
at com.arangodb.ArangoDriver.executeQuery(ArangoDriver.java:1877)
at com.arangodb.ArangoDriver.graphGetEdges(ArangoDriver.java:4135)
at x.y.z.database.arangodb.Arango.main(Arango.java:34)

I almost think it is a bug? 我几乎认为这是一个错误? Maybe a problem with newest versions? 最新版本可能有问题吗? Or do i miss something? 还是我想念什么?

Using latest versions.. 2.6.8 and driver 2.5.7 使用最新版本.. 2.6.8和驱动程序2.5.7

Update: if I use a nonexistent ID it returns zero results without exception and if i use an existing ID the same exception is thrown. 更新:如果我使用不存在的ID,它将无例外地返回零结果;如果我使用现有的ID,则将引发相同的异常。 that tells me that i used the right parameters, and the problem is most likely a bug.. 告诉我我使用了正确的参数,而问题很可能是错误。

As stj pointed out, there's a driver release fixing the initial problem: http://github.com/arangodb/arangodb-java-driver/releases . 正如stj所指出的,有一个驱动程序版本可以解决最初的问题: http ://github.com/arangodb/arangodb-java-driver/releases。

That should work fine with the following code: 使用以下代码应该可以正常工作:

CursorEntity<BaseDocument> r = driver.graphGetEdges("myGraph",
                               BaseDocument.class, "Person/1"); 
Iterator<BaseDocument> it = r.iterator();
while {
 it.hasNext()) {
   BaseDocument d = it.next();
   System.out.println(d.getDocumentHandle());
 }
}

The example code while (r.iterator().hasNext()) { ... } won't work because it will create a new Iterator object in each iteration and thus never finish while (r.iterator().hasNext()) { ... }的示例代码无法正常工作,因为它将在每次迭代中创建一个新的Iterator对象,因此永远无法完成

We added more examples howto work with ArangoDB graphs in java to the learn more section of the README 我们在README的“ learn more部分中添加了更多示例,说明了如何在Java中使用ArangoDB图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM