2

I'm trying create a relationship between 2 nodes A and B.

A potentially has several hundreds of connections and B may be a newly created node.

The way i'm doing it right now is by loading A with depth of 1, adding B as a child of A and then saving A with a depth of 1

Some example Groovy code,

def B = neo4jOperations.save(new B(), 0)
def A = neo4jOperations.load(A, idOfA, 1)
A.relationshipList().add(B)
neo4jOperations.save(A, 1) // This turns out to be slow since it is saving all the @EndNode of A, while it doesn't need to

This however, is VERY VERY slow due to neo4j loading and saving unnecessary nodes and relationships. I'm only interested to add one node i.e B to the existing relationships of A

Am I hitting an anti-pattern? Or is this the way its supposed to work? Is there a faster way i can do this?

Abbas Gadhia
  • 14,532
  • 10
  • 61
  • 73

1 Answers1

1

At the moment, the OGM will load all relationships of A, but will not save them if already persisted. It should not be this slow (which version do you use?). A workaround/hack is to try on a new Session, load A to depth 0, then add B to it and save. Make sure you don't use this session for any further work because things could go horribly wrong. Better still would be to send us some sample code and open an issue at https://github.com/neo4j/neo4j-ogm

Luanne
  • 19,145
  • 1
  • 39
  • 51
  • when you say new session, do you mean doing a neo4jOperations.clear() before and after i do my work? @luanne – Abbas Gadhia Dec 13 '16 at 01:15
  • Yes, please try that – Luanne Dec 13 '16 at 06:04
  • @Nerrve was this successful? I am seeing a similar situation where I believe that neo4j-ogm fails to see an old relationship as unchanged and still tries to map it. I've not been able to find a cause for that though yet. – geld0r Jan 15 '17 at 11:55