How to pass Collection Parameters to Repository Queries for Neo4J

ぃ、小莉子 提交于 2019-12-11 06:18:55

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/41376362/how-to-pass-collection-parameters-to-repository-queries-for-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!