Using Spring Data for Neo4J I want to pass a collection as a parameter to a repository query:
@Query("MATCH (product:Product) WHERE ANY(c IN product.categories WHERE c IN {categories}) RETURN product")
Iterable<Product> findAllWithCategories(@Param("categories") List<String> categories);
On the command line the corresponding query runs successfully and delivers the right results:
MATCH (product:Product) WHERE ANY(c IN product.categories WHERE c IN ["Märklin","Fleischmann"]) RETURN product
But from within Java no results are returned, when the findAllWithCategories method is invoked with a list of categories. The strange thing is that it looks like the correct http-request is sent to the DB:
request: {"statements":[{"statement":"MATCH (product:Product) WHERE ANY(c IN product.categories WHERE c IN {categories}) RETURN product","parameters":{"categories":["Märklin","Fleischmann"]},"resultDataContents":["graph"],"includeStats":false}]}
Any idea what goes wrong here? In general how can I pass collections as parameters to a repository query to Neo4J?
Edit The same query run without the Spring Data repository but with the more lower-level Neo4JTemplate gets the same result, which is really strange as the Query on the command line does what it should.
private final String FIND_PRODUCTS_WITH_CATEGORIES = "MATCH (product:Product) WHERE ANY(c IN product.categories WHERE c IN {categories}) RETURN product";
String[] categories = ...
Map<String, Object> map = new HashedMap<>();
map.put("categories", categories);
products = neo4j.queryForObjects(Product.class, FIND_PRODUCTS_WITH_CATEGORIES, map);
I don't think there is anything wrong with the query statement, but rather with the parameter of list type.
Edit After half a day I tried the bolt driver, instead of the http driver, and everything was okay (using the version 2.0.6 of the driver, version 2.1.0 throw a strange exception)
The queries are all right. The handover of arrays or lists as parameters to the queries works. The problem is the driver: no success using the http-driver, the bolt-driver seems to be buggy in the newest version 2.1.0. But with bolt 2.0.6 I got it running.