0
votes

The Cypher generated by spring data neo4j uses "$" to pass value, which will cause a error of Invalid Syntax by neo4j.

For example:

The Cypher generated by spring data neo4j for:

Optional<linkType> findById(Long id);

is

"MATCH ()-[r0:`linkType`]->() WHERE ID(r0)=$id WITH r0,STARTNODE(r0) AS n, ENDNODE(r0) AS m RETURN r0,n,m, ID(r0)"

This gets a error of Invalid Syntax. I fixed this by use @Query:

@Query("MATCH ()-[r0:`linkType`]->() WHERE ID(r0)={id} WITH r0,STARTNODE(r0) AS n, ENDNODE(r0) AS m RETURN r0,n,m, ID(r0)") Optional<linkType> findById(Long id);

However, when I want to use the PagingAndSortingRepository, I cannot use the @Query to fix this problem. Because it will add SKIP $sdnSkip LIMIT $sdnLimit at the edn automaticaly.

How can I fix this problem? Thanks.

1
Are rusing a really old version of neo4j? In neo4j 3.0, the {foo} syntax was deprecated in favor of the $foo syntax. In neo4j 4.0, the {foo} syntax was totally removed.cybersam
@cybersam I am using old old version of neo4j :2.2.3.Jie W
You should use {variable} syntax, but ensure that you import Query annotation (org.springframework.data.neo4j.annotation.Query) from neo4j package, but not default spring-data QueryAlexander Makarov

1 Answers

1
votes

You are using a really old version of neo4j (older than 3.0).

In neo4j 3.0, the {foo} syntax was deprecated in favor of the $foo syntax. In neo4j 4.0, the {foo} syntax was totally removed.

Instead of trying to support the obsolete {foo} syntax, you should upgrade your neo4j installation to a more recent (ideally, the latest) version of neo4j. If you have data to upgrade, you will have to upgrade in 2 steps: