【问题标题】:Neo4j with Spring Data QueryNeo4j 与 Spring 数据查询
【发布时间】:2014-01-30 21:19:22
【问题描述】:

我无法发现我做错了什么。我可以使用硬编码值在 neo4j 控制台上运行查询。

我正在尝试对我的存储库类执行以下查询:

@Query("START user=node({0}) \n" +
        "MATCH (anotherUser) \n" +
        "WHERE NOT (anotherUser<-[:MATCHES]-user) AND NOT user = anotherUser \n" +
        "RETURN anotherUser")
Iterable<User> findMatchesForUser(User user);

查询的结果应该是我作为参数传递的用户之间没有 :MATCHES 边缘的所有用户节点。

我得到以下异常:

SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement START user=node({0}) 
MATCH (anotherUser) 
WHERE NOT (anotherUser<-[:MATCHES]-user) AND NOT user = anotherUser 
RETURN anotherUser; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement START user=node({0}) 
MATCH (anotherUser) 
WHERE NOT (anotherUser<-[:MATCHES]-user) AND NOT user = anotherUser 
RETURN anotherUser; nested exception is `,' expected but `W' found

我也相信它与示例 here 是一致的。任何提示将不胜感激。

【问题讨论】:

  • 你使用哪个版本?
  • Spring 3.2、Spring-Data-neo4j 2.3.2 和 neo4j 1.8。我一直无法让 neo4j 2.0 运行,我在构建时遇到了“Unsupported major.minor version 51.0”,并决定暂时坚持使用 1.8。
  • 如果不能选择 2.0,我强烈建议升级到 Neo4j 1.9。为什么要坚持1.8?迁移应该不会太难,如果有的话。
  • 这是一个密码错误,所以你的查询在执行时被破坏了。
  • 也许您可以启用密码查询日志记录。我认为将org.neo4j.cypher 的日志级别设置为 DEBUG 会有所帮助

标签: neo4j spring-data spring-data-neo4j spring-data-graph


【解决方案1】:

我能够通过以下查询获得相同的结果:

@Query("START n=node({0}), a=node(*) \n" +
        "MATCH (n)-[r?:MATCHES]->(a) \n" +
        "WHERE has(a.__type__) AND r IS NULL AND a <> n \n" +
        "RETURN a");
Iterable<User> findMatchesForUser(User user);

由于我仍然无法真正理解的原因,我必须添加 has(a.type) 才能使我的查询正常工作,否则它会抛出“Could not write JSON: 'type ' 尝试序列化时找不到 NodeImpl#0 的属性。

【讨论】:

  • 但这是一个非常低效的查询,不会那样做。
  • @MichaelHunger,你认为我可以做些什么来提高查询性能?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多