- 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
Cypher query vs cypher dsl in spring data neo4j
-
01-07-2023 - |
Question
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
Solution
OTHER TIPS
Not an answer, but some feedback:
The Cypher-DSl https://github.com/neo4j-contrib/cypher-dsl has been rebooted last year and is now an integral part of Spring Data Neo4j 6.
Our new docs spot an example: https://docs.spring.io/spring-data/neo4j/docs/6.0.5/reference/html/#faq.custom-queries-and-custom-mappings All statements build from the DSL can be passed to the Neo4j Template.
I hope someone finds this useful.