Cypher query vs cypher dsl in spring data neo4j

2019-09-09 12:10发布

问题:

I want to know about neo4j dsl recommendation in Spring data neo4j framework.
As of now I used to create repository interface extending from GraphRepository,NamedIndexRepository etc. and write my custom methods with my custom cypher query with @Query annotation as below:

@Query(value="START root=node:__types__(className='com.data.EntityNode') WHERE root.id={0} and "
        + "root.type={1} return root")  
T findByIdAndType(String id, String type);  

above method works nicely as far as I consider the static query. but right now I am in need to use some other way where I can generate cypher query depending upon my need !. then I came across neo4j dsl library which looks like a solution to my requirement.
ref: link-1 link-2

My question is:

  1. is it OK to use neo4j dsl lib in Spring data neo4j (I am using v2.1.0 RELEASE) ? or
  2. is there any other way to generate dynamic cypher query in spring data neo4j for given set of situation ? and more interesting
  3. is it possible to generate query from cypher dsl and pass it to my custom repository interface, execute them and get result (I mean @Query value)? because if yes then I dont have to add major changes to my existing design.

Thanks

回答1:

  1. Update to 3.0.1.RELEASE
  2. It is ok to use cypher DSL
  3. As annotations are compile time and Cypher DSL is runtime you cannot use them there, but
  4. you can inherit from CypherDSLRepository which adds some nice methods to your repository