Reputation: 11
I'm new to ArangoDB and trying to do a few very basic queries. 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
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. that tells me that i used the right parameters, and the problem is most likely a bug..
Upvotes: 1
Views: 333
Reputation: 6077
As stj pointed out, there's a driver release fixing the initial problem: 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
We added more examples howto work with ArangoDB graphs in java to the learn more
section of the README
Upvotes: 2