I'm using SDN 3.1.0.RELEASE. And i trying danamic label query like
@Query("MATCH (n:{0}) RETURN n")
public List<SimpleArticle> findAllByDomain(String domain);
and give String parameter like SimpleArticle.class.getSimpleName() when i launched test code, i met "SyntaxException At {0}"
so i change query to
@Query("MATCH (n:`{0}`) RETURN n")
this code is work but don't find Domain node.
result log is "Executing remote cypher query: MATCH (n:`{0}`) RETURN n params {0=SimpleArticle}"
so i run this cypher query in query broswer
MATCH (n:`SimpleArticle`) RETURN n ; 
It works and find node.
Can i use dynamic labels in @Query ?
Labels cannot be parameterized. The rationale for this is that different labels might result in different query plans. A parameterized query is always using the same query plan - therefore it's not possible.
The only way to use "semi"-dynamic labels is by using string concatenation or by Cypher DSL.
Although definitely too late for the poster, this thread was one of the first to come up when searching for it. In newer Versions you can parameterize searching for a specific label:
@Query("MATCH (n:`:#{literal(#label)}`) RETURN n") 
List<BaseClass> findByLabel(String label);
Source: https://docs.spring.io/spring-data/neo4j/reference/appendix/custom-queries.html#literal-extension
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With