运行 查询时出现 Neo4j NullPointerException

Neo4j NullPointerException while running query

这是我的配置:

@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();
}

每次我想从 neo4j 获取结果时,它都会给我一个 nullPointerError,如图所示:

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)

其中指定的第 57 行是:

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

我想知道可能是什么问题?我确保会话不为空。

如果您没有可将结果映射到的节点实体,RestModelMapper 将在 Neo4j-OGM 2.0.1(SDN 4.1.1 所依赖的)中抛出 NullPointerException。这已在 Neo4j OGM 2.0.2 中修复- https://github.com/neo4j/neo4j-ogm/issues/150

请检查返回的节点是否可以映射到节点实体(它们的标签应该匹配),然后覆盖 neo4j-ogm-code 和驱动程序依赖项以使用 2.0.2。