1

Adding, deleting, updating vertices is fine but when attempting to add edges I get the following exception stating edge additions not supported. Can anyone advise how to add edges when using remote client? Thanks in advance.

java.lang.IllegalStateException: Edge additions not supported at org.apache.tinkerpop.gremlin.structure.Vertex$Exceptions.edgeAdditionsNotSupported(Vertex.java:175) at org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex.addEdge(ReferenceVertex.java:47)

Link to code: https://gist.github.com/ptclarke/45472fa5c268a6e8441e4c35615194aa

ptc
  • 734
  • 5
  • 11

1 Answers1

5

The Vertex object returned from a remote request is detached from the graph and is immutable so if you try to do this:

Vertex v = g.V(id).next()
v.addEdge(...)

it will fail as you are trying to add edges to an immutable object that has no connection to the remote graph. You should use Gremlin to add your edges and not operate on the returned objects directly:

g.V(id).addE(...).to(...)
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • my answer is still right - though i had a bug in my code which i just fixed. sorry about that. – stephen mallette Nov 05 '18 at 18:30
  • Thanks Florian and Stephen, I have added link to gist with code, I am sure Stephen is right, however his sample syntax does not parse, possibly I am not using the correct libraries? Any assistance much appreciated. – ptc Nov 05 '18 at 18:56
  • `g.V(from.id()).next().addEdge(label, g.V(to.id()).next());` fails for the reason i stated. As soon as you do that first `next()` you return a "detached" `Vertex` and you can't call `addEdge()` on that. just do as i showed above, `g.V(from.id()).addE(label).to(V(to.id())).next()` – stephen mallette Nov 05 '18 at 19:34
  • Thanks Stephen, that worked but lead to a serializatiion error which I will have to investigate further tomorrow: io.netty.handler.codec.DecoderException: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: org.apache.tinkerpop.shaded.kryo.KryoException: Encountered unregistered class ID: 65536 Serialization trace: id (org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceEdge) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:98) – ptc Nov 06 '18 at 18:15
  • that error typically means that you need to align your versions of TinkerPop on server and client. check the version of TinkerPop that is shipped with the JanusGraph version you are using and make sure you use that version on the client. – stephen mallette Nov 06 '18 at 18:32
  • Thanks Stephen, much appreciate your response. I am running JanusGraph 0.3.0 with Cassandra 3.11.3 and ES 6.4.0, I was using Tinkerpop 3.3.1 libraries on the client and have changed that to 3.3.3 which is the supported release for JG 0.3.0, have also changed from gyro message serializer GryoMessageSerializerV1d0 to V3d0 (both are in list of serializers on back end), but still get the problem. Will investigate serialization error further and log seperate question if unable to resolve. – ptc Nov 07 '18 at 23:14