Search code examples
neo4j-ogm

Incosistent Results in neo4j-ogm - Related to Session Scope?


We developing a Spring Boot REST Application using Spring Data Neo4J. Recently we upgraded to Spring Data Neo4j 4.2 along with ogm 2.1.1 and using the embedded driver.

In our application we provide some GET operations in which we build some object structures from nodes fetched from Neo4j.

As soon as we are processing multiple requests in parallel, we are facing inconsitent results, i.e., our object structures have a different size on each request.

We are not really sure about the reasons for this inconsistent behavior - but probably it is related to the session handling in OGM? We know that Sessions are not thread safe, but we have no idea how to deal with this issue in SD 4.2. Before 4.2 we changed the sesssion scope to prototype when defining the session bean, but the configuration changed in SD 4.2

Configuration before 4.2

@Bean
@Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
    return;
}

We could narrow the source of our problems to the place where we are loading elements from Neo4j via a Repository class:

repository.findOne(id,-1);

If we place this call in a synchronized block, no inconsistencies occur.

synchronized (this) {
    repository.findOne(id,-1);
}

We are probably missing some important point using SD 4.2/ogm, but could not find any useful information in the documentation, and on the web. Is it still possible/necessary to change the sesssion scope in SD 4.2?


Solution

  • This is a bug in the OGM. See: https://jira.spring.io/browse/DATAGRAPH-951

    We hope to have a fix for this in the next version (OGM 2.1.2).