0

I'm not being able to catch what I'm doing wrong. I'm able to run the query on neo4j console with hardcoded values.

I'm trying to do the following query on my repository class:

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

The result of the query should be all User nodes that doesn't have a :MATCHES edge between the user I'm passing as an argument.

I get the following exception:

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

I also believe it's inline with the example here. Any tip would be appreciated.

rantunes
  • 376
  • 4
  • 7
  • Which versions do you use? – Michael Hunger Jan 13 '14 at 01:32
  • Spring 3.2, Spring-Data-neo4j 2.3.2, and neo4j 1.8. I was never able to get neo4j 2.0 running, I got stuck with "Unsupported major.minor version 51.0" while building and decided to stick with 1.8 for now. – rantunes Jan 13 '14 at 02:12
  • 1
    I'd strongly recommend to upgrade to Neo4j 1.9 if 2.0 isn't an option. Why stick with 1.8? The migration shouldn't be too hard, if any. – tstorms Jan 14 '14 at 09:50
  • It is a cypher error, so somehow your query is broken when it is executed. – Michael Hunger Jan 14 '14 at 13:52
  • 1
    Perhaps you can enable cypher query logging. I think setting the log level of `org.neo4j.cypher` to DEBUG helps – Michael Hunger Jan 14 '14 at 13:52
  • Upgrading to 2.0 was just a lot of trouble. The issue I mentioned before was because my maven was building with Java 1.6, but even after fixing, I kept running into endless issues. – rantunes Jan 15 '14 at 03:23
  • I was able to upgrade to 1.9 with no issues, which didn't made any difference. I'm also experimenting with the following query that should yield same results: "START n=node({0}), a=node(*) MATCH (n)-[r?:MATCHES]->(a) WHERE r IS NULL AND a <> n RETURN a", and this time I get a "Could not write JSON: '__type__' property not found for NodeImpl#0." Sounds more like a Jackson issue, but still related to Spring Data. – rantunes Jan 15 '14 at 03:26

1 Answers1

0

I was able to get the same result with the following query:

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

For a reason I still can't really understand, I had to add the has(a.type) for my query to work, or it would throw "Could not write JSON: 'type' property not found for NodeImpl#0" when trying to serialize it.

rantunes
  • 376
  • 4
  • 7