I have the following Spring Data Neo4j OGM Repository method:
@Query("MATCH (root:Location) " +
"WHERE root.id IN $locationIds " +
"WITH root " +
"OPTIONAL MATCH (root)-[:CONTAINS*0..]->(descendant:Location) " +
"OPTIONAL MATCH (ascendant:Location)-[:CONTAINS*0..]->(root) " +
"WITH COLLECT(root.id) AS listRoot, COLLECT( DISTINCT ascendant.id) AS listAscendant, COLLECT( DISTINCT descendant.id) AS listDescendant WITH apoc.coll.union(listDescendant, apoc.coll.union(listRoot, listAscendant)) AS dadLocationIds " +
"WITH dadLocationIds " +
"RETURN apoc.coll.intersection(dadLocationIds, $specifiedLocationIds) as output")
Set<Long> locationsHaveAnyDirectOrAscendantOrDescendantRelationshipsWithSpecifiedLocations(Set<Long> locationIds, Set<Long> specifiedLocationIds);
this method fails with the following exception:
org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.util.ArrayList<?>] to type [@org.springframework.data.neo4j.annotation.Query java.util.Set<java.lang.Long>] for value '[[5]]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Collections$SingletonList<?>] to type [@org.springframework.data.neo4j.annotation.Query java.lang.Long]
How to properly return Set
of ids for intersection?
UPDATED
MATCH (root:Location)
WHERE root.id IN [61]
WITH root
OPTIONAL MATCH (root)-[:CONTAINS*0..]->(descendant:Location)
OPTIONAL MATCH (ascendant:Location)-[:CONTAINS*0..]->(root)
WITH COLLECT(root.id) AS listRoot, COLLECT(DISTINCT ascendant.id) AS listAscendant, COLLECT(DISTINCT descendant.id) AS listDescendant
WITH listDescendant + listRoot + listAscendant AS dadLocationIds
WITH dadLocationIds
WITH apoc.coll.intersection(dadLocationIds, [60, 58]) as output
RETURN output
and output from Neo4j browser:
╒════════╕
│"output"│
╞════════╡
│[60] │
└────────┘
UPDATED 1
The query works fine when I change it to the following:
"WITH apoc.coll.intersection(dadLocationIds, $specifiedLocationIds) as intersectionIds " +
"MATCH (l:Location) WHERE l.id IN intersectionIds " +
"RETURN l")
Set<Location> locationsHaveAnyDirectOrAscendantOrDescendantRelationshipsWithSpecifiedLocations(Set<Long> locationIds, Set<Long> specifiedLocationIds);