Search code examples
javaneo4jnullpointerexceptionspring-data-neo4j-4neo4j-ogm

Neo4j NullPointerException while running query


this is my configuration:

@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
    org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
    config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
                                .setCredentials("neo4j", "neo4j")
                                .setURI("http://localhost:7474");
    return config;
}

@Override
public SessionFactory getSessionFactory() {
    return new SessionFactory(getConfiguration(), "movies.spring.data.neo4j.domain");
}

@Bean
@Override
// @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
    return getSessionFactory().openSession();
}

everytime i want to get the result from neo4j and it hits me a nullPointerError as shown:

Exception in thread "main" java.lang.NullPointerException
    at org.neo4j.ogm.context.RestModelMapper.mapEntity(RestModelMapper.java:153)
    at org.neo4j.ogm.context.RestModelMapper.map(RestModelMapper.java:76)
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:94)
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:73)
    at org.neo4j.ogm.session.Neo4jSession.query(Neo4jSession.java:313)
    at movies.spring.data.neo4j.controllers.BenchmarkDeleteController.run(BenchmarkDeleteController.java:57)

where the specified line 57 is:

Result results = neoSession.query("MATCH (n:USER) WHERE n.isBanned={param} RETURN n as user",
        Collections.<String, Object>singletonMap("param", 1));

I wonder what could be the problem? I made sure that the session isnt null.


Solution

  • If you do not have a node entity that the results can be mapped to, the RestModelMapper throws a NullPointerException in Neo4j-OGM 2.0.1 (which SDN 4.1.1 depends on). This was fixed in Neo4j OGM 2.0.2- https://github.com/neo4j/neo4j-ogm/issues/150

    Please check that the nodes returned can be mapped to node entities (their labels should match) and then override the neo4j-ogm-code and driver dependencies to use 2.0.2.