Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm working on a Spring Data / Neo4j-based recommender service and ran into an issue with the
@Query
annotation. I'm trying to pass a property (the
network_userid
) into a Cypher query:
package io.woolford.neo4j.repository;
import io.woolford.neo4j.entity.PageUrl;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface RecommendationsRepository extends Neo4jRepository<PageUrl, Long> {
@Query("MATCH (n {id: '$network_userid' }) RETURN n") // simplified query for brevity
List<PageUrl> getRecommendations(@Param("network_userid") String network_userid);
I thought it'd be as simple as putting a dollar-sign in front of the property name to substitute the property name with the property value (as above). I expected this:
MATCH (n {id: '1447e32a-3381-4e61-a8ae-9a05b8df4ddb'}) RETURN n
When I switched on debugging, it looks like the Cypher query hasn't replaced the property with the value:
[nio-8080-exec-1] o.n.o.drivers.bolt.request.BoltRequest : Request: MATCH (n {id: '$network_userid' }) RETURN n with params {0=1447e32a-3381-4e61-a8ae-9a05b8df4ddb, network_userid=1447e32a-3381-4e61-a8ae-9a05b8df4ddb}
For good measure, I did a packet capture to see what's being sent across the wire:
...d'...............+MATCH (n {id: '$network_userid' }) RETURN n..0.$1447e32a-3381-4e61-a8ae-9a05b8df4ddb.network_userid.$1447e32a-3381-4e61-a8ae-9a05b8df4ddb......?..n.....
... which, again, suggests that the property substitution isn't happening.
Can you see what I'm doing wrong?
Source code: https://github.com/alexwoolford/snowplow-neo4j-recommender
The only problem with your query is that you are escaping the '$network_userid'
like a string but you should do:
@Query("MATCH (n {id: $network_userid }) RETURN n")
without the string literal indication.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.