3
votes

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 ?

1
This question is a old version sdn. Now you can use ` @Query("MATCH (movie:Movie {title={0}}) RETURN movie")`reperion

1 Answers

4
votes

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.