带有Spring Data Query的Neo4j

时间:2014-01-11 23:10:09

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

我无法理解我做错了什么。我能够使用硬编码值在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一致。任何提示都将不胜感激。

1 个答案:

答案 0 :(得分:0)

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

@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 )以使我的查询正常工作,否则会抛出“无法写入JSON:”类型尝试序列化时,找不到“NodeImpl#0的属性”。