You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Repository query method with 'contains' on list property generates incorrect cypher query #2444
If I want to write a repository query method to find the nodes which contain a given item in their items list property, I expect the following to work:
interface TestNodeRepository: Neo4jRepository<TestNode, Long> {
fun findByItemsContains(item: String): TestNode?
}
However, executing this method yields no results, because it generates the following cypher query:
MATCH (n:`TestNode`) WHERE n.items CONTAINS $item RETURN n{.description, .id, .items, __nodeLabels__: labels(n), __internalNeo4jId__: id(n)}
So it uses the CONTAINS keyword, which in cypher is used for partial String matching. I would have expected it to create the following query:
MATCH (n:`TestNode`) WHERE $item IN n.items RETURN n{.description, .id, .items, __nodeLabels__: labels(n), __internalNeo4jId__: id(n)}
My first thought was that maybe I should modify my query method to use In instead of Contains, but that only works the other way around (matching a property against a list of possible items), e.g.: fun findByDescriptionIn(descriptions: List<String>): TestNode?, which correctly generates a cypher query using the IN keyword.
Am I missing something (not so) obvious here, or is this indeed a bug?
Hey. This is an interesting one, takes for taking the time to create it, much appreciated
In Spring Data commons CONTAINS is usually defined as the String Op you described and how we implemented it.
Can you share the domain class(es), please?
It might be worth considering that if we find a list on the entity to generate an actual IN condition.
Thank you, @rlippolis Thanks to the Cypher-DSL based builder, this was an easy fix / improvement. Thanks again for reporting it and providing the reproducer.
Activity
michael-simons commentedon Nov 18, 2021
Hey. This is an interesting one, takes for taking the time to create it, much appreciated
In Spring Data commons
CONTAINSis usually defined as the String Op you described and how we implemented it.Can you share the domain class(es), please?
It might be worth considering that if we find a list on the entity to generate an actual
INcondition.Things that interest me:
Thanks in advance.
rlippolis commentedon Nov 18, 2021
Hey Michael, thanks for your quick response.
See the domain class in my sample project: https://github.com/rlippolis/spring-data-neo4j-listcontains-test/blob/main/src/main/kotlin/com/example/neo4jlistcontainstest/TestNode.kt
I'm not using any custom converters. The property currently is a
List<String>. I've tested it with aSetas well as with anArray, same result.GH-2444 - Use either `property CONTAINS string` or `item IN collectio…
GH-2444 - Use either `property CONTAINS string` or `item IN
GH-2444 - Use either `property CONTAINS string` or `item IN collectio…
GH-2444 - Use either `property CONTAINS string` or `item IN collectio…
michael-simons commentedon Nov 18, 2021
Thank you, @rlippolis Thanks to the Cypher-DSL based builder, this was an easy fix / improvement. Thanks again for reporting it and providing the reproducer.
rlippolis commentedon Nov 18, 2021
Awesome, thanks for the quick response and fix, @michael-simons! 👍
GH-2444 - Apply negotiation to collections as well.
GH-2444 - Apply negotiation to collections as well.
GH-2444 - Apply negotiation to collections as well.
GH-2444 - Apply negotiation to collections as well.
spring-projectsGH-2444 - Use either `property CONTAINS string` or `it…