Reputation: 10127
I have the following custom query in my Neo4jRepository
(I'm using Spring Boot with Spring Data Neo4j):
@Query("MATCH (n:Component) WHERE n.path =~ '/path/{0}/.*/{1}' RETURN n")
Component findByTenantAndName(String tenant, String name);
When I run this query within the application it returns null
with the following log statement:
2018-01-12 10:58:27.744 INFO 74294 --- [nio-8080-exec-1] o.n.o.drivers.bolt.request.BoltRequest : Request: MATCH (n:Component) WHERE n.path =~ '/path/{0}/.*/{1}' RETURN n with params {0=foo, 1=baz}
2018-01-12 10:58:27.763 WARN 74294 --- [nio-8080-exec-1] d.c.a.service.MyService : Could not find parent component named 'baz' for tenant 'foo'
But, if I go to the Cypher backend at http://localhost:7474 and run the query:
MATCH (n:Component) WHERE n.path =~ '/path/foo/.*/baz' RETURN n
I get exactly one Component
result with path /path/foo/bar/baz
. What's wrong with my custom query?
Upvotes: 0
Views: 174
Reputation: 27018
@Query("MATCH (n:Component) WHERE n.path =~ {0} RETURN n")
Component findByTenantAndName(String query);
And from the service where you call this. pass the whole regex like this
String query = "/path/<tenant>/.*/<name>"; // replace tenant and name with actual variables.
findByTenantAndName(query)
Upvotes: 2