Neo4j with Spring Data Query

215 views Asked by At

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.

1

There are 1 answers

2
rantunes On BEST ANSWER

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.