Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-13-2021 11:08 PM
hi guys I need help in the Spring boot neo4j repository
@Query(" MATCH (u:User) WHERE u.userId =~ '(?i)'+$userId RETURN u.userId ")
String userExistsById(@Param("userId") String pStrUserId);
instead of writing query here (inside the interface repo) is there any way can I substitute the query from external properties file
This was a simple query example but I actually had a big query which looks very bad and difficult to understand if I put it in interface file.
07-28-2022 06:58 AM
Yes, you should be able to do this. I think I would try to use the @Value annotation in Spring. I haven't used that annotation to source in a query before, but theoretically, I think it would still work. Couple links down below for more info on it. Hope this helps!
07-28-2022 10:15 PM
You can use named queries with Spring Data Neo4j.
This way you just define the method as it is without the query annotation:
interface UserRepository extends Neo4jRepository<User, IdentifierType> {
User userExistsById(@Param("userId") String pStrUserId);
}
And define the query in META-INF a file called neo4j-named-queries.properties (default name) where you define the query in this form:
UserRepository.userExistsById="MATCH (u:User) WHERE u.userId =~ '(?i)'+$userId RETURN u.userId"
An example can be found in our test base:
https://github.com/spring-projects/spring-data-neo4j/blob/ee60a1faf643f3d033c1d40eb3b3ed527bf3cb46/s...
https://github.com/spring-projects/spring-data-neo4j/blob/78bb07356bd6d646bbc08ad1adcb1509c51ab655/s...
All the sessions of the conference are now available online