问题
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:
- is it OK to use
neo4j dsl
lib in Spring data neo4j (I am using v2.1.0 RELEASE) ? or - is there any other way to generate dynamic cypher query in spring data neo4j for given set of situation ? and more interesting
- 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:
- Update to 3.0.1.RELEASE
- It is ok to use cypher DSL
- As annotations are compile time and Cypher DSL is runtime you cannot use them there, but
- you can inherit from CypherDSLRepository which adds some nice methods to your repository
来源:https://stackoverflow.com/questions/22989614/cypher-query-vs-cypher-dsl-in-spring-data-neo4j