I have the below code in my java program that queries janusgraph to create vertices and edges if they don't exist already.
Vertex v1 = g.V().has(<key1>,<value1>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label1>,<key1>,<value1>));
Vertex v2 = g.V().has(<key2>,<value2>).tryNext().orElseGet(()->
tx.addVertex(T.label,<label2>,<key2>,<value2>));
Vertices v1 and v2 get created if they don't exist.
..code to check if an edge exists between the two vertices..
..if there is no edge between the two, create an edge
v1.addEdge(<label3>,v2,<key3>,<value3>)
If the vertices are newly created, the code works fine and the edge also gets created between the two vertices. But if the vertices already exist in the DB, the edge doesn't get created. The difference I could find between the two cases is that v1 and v2 are of 'StandardVertex' type when they are newly created and they are of 'CacheVertex' type when they already exist. 'addEdge' is a valid method in both cases. Yet the edge doesn't get created.