这是我的配置:
@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));
我想知道可能是什么问题?我确保会话不是空的。
答案 0 :(得分: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。