【发布时间】:2014-05-25 22:55:23
【问题描述】:
我正在运行 Neo4j 2.0.1。连同 2.0.1 的空间插件。连同 2.0.1 的 JDBC 驱动程序。 我创建了一个简单的点图层和一个索引来进行空间查询。如果我在浏览器中输入以下查询,则会返回相应的节点:
START n=node:geom('withinDistance:[15.0,60.0, 200.0]') RETURN n
我在我的 servlet 中编写了一个方法来发送这个查询:
//connect to database
try {
if(connection == null || connection.isClosed())
{
Class.forName("org.neo4j.jdbc.Driver"); // load jdbc driver
connection = DriverManager.getConnection("jdbc:neo4j://localhost:7474");
}
} catch (SQLException e) {
System.out.println("could not connect do DB: <br>" + e.getCause()
+ "<br>" + e.getMessage());
} catch (ClassNotFoundException e) {
System.out.println("Could not load JDBC DRIVER");
e.printStackTrace();
}
然后,我正在尝试向服务器发送请求:
@Path("findRange")
@GET
@Produces(MediaType.TEXT_HTML)
public String findRange(@QueryParam("lat") double lat,
@QueryParam("lon") double lon,
@QueryParam("d") double distance)
{
connectToDbIfNecessary();
try(PreparedStatement p = connection.prepareStatement(FIND_WITHIN_RANGE))
{
p.setObject(1, lat);
p.setObject(2, lon);
p.setObject(3, distance);
ResultSet rs = p.executeQuery();
return getServerResponse(rs);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "failure during geospatial query:\n"+e.getErrorCode()+"<br>\n"+e.getMessage()+"<br>"+e.getCause();
}
}
我发送的准备好的声明是:
private static final String FIND_WITHIN_RANGE = "START n=node:geom('withinDistance:[{1},{2}, {3}]') RETURN n";
当我在 Tomcat 7.0.53 上执行此操作时,出现以下异常:
地理空间查询失败:0 执行查询 START 时出错 n=node:geom('withinDistance:[{1},{2}, {3}]') RETURN n with params {3=1.0E8, 2=60.5, 1=14.9} java.lang.RuntimeException: 执行错误 密码语句 [{code=Neo.DatabaseError.Statement.ExecutionFailure, message=null, stackTrace=java.lang.NullPointerException 在 org.neo4j.gis.spatial.indexprovider.LayerNodeIndex.query(LayerNodeIndex.java:249) 在 org.neo4j.gis.spatial.indexprovider.LayerNodeIndex.query(LayerNodeIndex.java:293) 在 org.neo4j.cypher.internal.spi.v2_0.TransactionBoundExecutionContext$NodeOperations.indexQuery(TransactionBoundExecutionContext.scala:166) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:113) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations.org$neo4j$cypher$internal$compiler$v2_0$spi$ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$super$indexQuery(ExceptionTranslatingQueryContext.scala:142) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$anonfun$indexQuery$1.apply(ExceptionTranslatingQueryContext.scala:142) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$anonfun$indexQuery$1.apply(ExceptionTranslatingQueryContext.scala:142) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext.org$neo4j$cypher$internal$compiler$v2_0$spi$ExceptionTranslatingQueryContext$$translateException(ExceptionTranslatingQueryContext.scala:149) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations.indexQuery(ExceptionTranslatingQueryContext.scala:142) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:113) 在 org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anonfun$2$$anonfun$applyOrElse$2.apply(EntityProducerFactory.scala:66) 在 org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anonfun$2$$anonfun$applyOrElse$2.apply(EntityProducerFactory.scala:64) 在 org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anon$1.apply(EntityProducerFactory.scala:35) 在 org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anon$1.apply(EntityProducerFactory.scala:34) 在 org.neo4j.cypher.internal.compiler.v2_0.pipes.StartPipe$$anonfun$internalCreateResults$1.apply(StartPipe.scala:34) 在 org.neo4j.cypher.internal.compiler.v2_0.pipes.StartPipe$$anonfun$internalCreateResults$1.apply(StartPipe.scala:33) 在 scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371) 在 org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator$$anonfun$hasNext$1.apply$mcZ$sp(ClosingIterator.scala:38) 在 org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:37) 在 org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:37) 在 org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator.failIfThrows(ClosingIterator.scala:91) 在 org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator.hasNext(ClosingIterator.scala:37) 在 org.neo4j.cypher.internal.compiler.v2_0.PipeExecutionResult.hasNext(PipeExecutionResult.scala:166) 在 scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327) 在 scala.collection.convert.Wrappers$IteratorWrapper.hasNext(Wrappers.scala:29) 在 org.neo4j.cypher.internal.compiler.v2_0.PipeExecutionResult$$anon$1.hasNext(PipeExecutionResult.scala:74) 在 org.neo4j.server.rest.transactional.ExecutionResultSerializer.writeRows(ExecutionResultSerializer.java:291) 在 org.neo4j.server.rest.transactional.ExecutionResultSerializer.statementResult(ExecutionResultSerializer.java:103) 在 org.neo4j.server.rest.transactional.TransactionHandle.executeStatements(TransactionHandle.java:251) 在 org.neo4j.server.rest.transactional.TransactionHandle.commit(TransactionHandle.java:189) 在 org.neo4j.server.rest.transactional.TransactionHandle.commit(TransactionHandle.java:109) 在 org.neo4j.server.rest.web.TransactionalService$2.write(TransactionalService.java:198) 在 com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71) 在 com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57) 在 com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306) 在 com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437) 在 com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) 在 com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) 在 com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) 在 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) 在 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:848) 在 org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698) 在 org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1506) 在 org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112) 在 org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1477) 在 org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503) 在 org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211) 在 org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096) 在 org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432) 在 org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175) 在 org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030) 在 org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) 在 org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52) 在 org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) 在 org.eclipse.jetty.server.Server.handle(Server.java:445) 在 org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:268) 在 org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229) 在 org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358) 在 org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) 在 org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) 在 java.lang.Thread.run(Thread.java:722) }]
当我通过手动向文档中指定的 URL 发送 http 请求来执行查询时,我没有收到异常。 我不知道为什么会发生此异常。谁能指出我正确的方向?
编辑:似乎索引查询无法参数化。但是,如果我按照 Stefan Armbruster 的建议进行操作,则会出现新的异常(也许这是 0.12 空间实现中的另一个问题)。
地理空间查询失败:0 错误执行查询 START n=node:geom({1}) RETURN n with params {1='withinDistance:[14.9,60.5,1.0E8]'} java.lang.RuntimeException: 执行密码语句时出错 [{code=Neo.DatabaseError.Statement.ExecutionFailure, message=only within, withinDistance 和 bbox 被实现。, stackTrace=java.lang.UnsupportedOperationException: only within, withinDistance and bbox 已实现。在 org.neo4j.gis.spatial.indexprovider.LayerNodeIndex.query(LayerNodeIndex.java:281) 在 org.neo4j.gis.spatial.indexprovider.LayerNodeIndex.query(LayerNodeIndex.java:293) 在 org.neo4j.cypher.internal .spi.v2_0.TransactionBoundExecutionContext$NodeOperations.indexQuery(TransactionBoundExecutionContext.scala:166) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery(DelegatingQueryContext.scala:113) 在 org.neo4j.cypher.internal .compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations.org$neo4j$cypher$internal$compiler$v2_0$spi$ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$super$indexQuery(ExceptionTranslatingQueryContext.scala:142) 在 org.neo4j.cypher.internal.compiler .v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$anonfun$indexQuery$1.apply(ExceptionTranslatingQueryContext.scala:142) at org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations$$ anonfun$indexQuery$1.apply(ExceptionTranslatingQueryContext.scala:142) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext.org$neo4j$cypher$internal$compiler$v2_0$spi$ExceptionTranslatingQueryContext$$translateException(ExceptionTranslatingQueryContext .scala:149) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.ExceptionTranslatingQueryContext$ExceptionTranslatingOperations.indexQuery(ExceptionTranslatingQueryContext.scala:142) 在 org.neo4j.cypher.internal.compiler.v2_0.spi.DelegatingOperations.indexQuery (DelegatingQueryContext.scala:113) at org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anonfun$2$$anonfun$applyOrElse$2.apply(EntityProducerFactory.scala:66) at org.neo4j.cypher .internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anonfun$2$$anonfun$applyOrElse$2.apply(EntityProducerFactory.scala:64) at org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$ $anon$1.apply(EntityP roducerFactory.scala:35) 在 org.neo4j.cypher.internal.compiler.v2_0.executionplan.builders.EntityProducerFactory$$anon$1.apply(EntityProducerFactory.scala:34) 在 org.neo4j.cypher.internal.compiler.v2_0。 Pipes.StartPipe$$anonfun$internalCreateResults$1.apply(StartPipe.scala:34) at org.neo4j.cypher.internal.compiler.v2_0.pipes.StartPipe$$anonfun$internalCreateResults$1.apply(StartPipe.scala:33) at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371) at org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator$$anonfun$hasNext$1.apply$mcZ$sp(ClosingIterator.scala:38 ) 在 org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator$$anonfun$hasNext$1 的 org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:37) .apply(ClosingIterator.scala:37) at org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator.failIfThrows(ClosingIterator.scala:91) at org.neo4j.cypher.internal.compiler.v2_0.ClosingIterator.hasNext(ClosingIterator .scala:37) 在 org.neo4 j.cypher.internal.compiler.v2_0.PipeExecutionResult.hasNext(PipeExecutionResult.scala:166) 在 scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327) 在 scala.collection.convert.Wrappers$IteratorWrapper。 hasNext(Wrappers.scala:29) at org.neo4j.cypher.internal.compiler.v2_0.PipeExecutionResult$$anon$1.hasNext(PipeExecutionResult.scala:74) at org.neo4j.server.rest.transactional.ExecutionResultSerializer.writeRows( ExecutionResultSerializer.java:291) 在 org.neo4j.server.rest.transactional.ExecutionResultSerializer.statementResult(ExecutionResultSerializer.java:103) 在 org.neo4j.server.rest.transactional.TransactionHandle.executeStatements(TransactionHandle.java:251) 在 org .neo4j.server.rest.transactional.TransactionHandle.commit(TransactionHandle.java:189) at org.neo4j.server.rest.transactional.TransactionHandle.commit(TransactionHandle.java:109) at org.neo4j.server.rest.web .TransactionalService$2.write(TransactionalService.java:198) 在 com.sun.jersey.core.impl.provider.entity.Stream ingOutputProvider.writeTo(StreamingOutputProvider.java:71) 在 com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57) 在 com.sun.jersey.spi.container.ContainerResponse.write( ContainerResponse.java:306) 在 com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437) 在 com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:第1349章)在com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)在com .sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) 在 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) 在 javax.servlet.http .HttpServlet.service(HttpServlet.java:848) 在 org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698) 在 org.eclipse.jetty.servl et.ServletHandler$CachedChain.doFilter(ServletHandler.java:1506) at org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter( ServletHandler.java:1477) 在 org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503) 在 org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211) 在 org.eclipse .jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096) 在 org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432) 在 org.eclipse.jetty.server.session.SessionHandler.doScope (SessionHandler.java:175) 在 org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030) 在 org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) 在org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52) 在 org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) 在 org.eclipse.jetty.server .Server.handle(Server.java:445) 在 org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:268) 在 org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229) 在org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) 在 org.eclipse.jetty.util 的 org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)。 thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) at java.lang.Thread.run(Thread.java:722) }]
这个问题似乎类似于this one here from the mid of 2013。
【问题讨论】:
标签: neo4j neo4j-spatial