使用OGM在自定义Cypher查询中的深度始终为0? [英] Depth in custom Cypher queries with OGM always 0?

查看:96
本文介绍了使用OGM在自定义Cypher查询中的深度始终为0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在评估OGM/Spring Data Neo4j的用例,并遇到以下问题:

I'm currently evaluating OGM / Spring Data Neo4j for a use case and came upon the following problem:

通过Spring Data @Query注释或直接通过Neo4j Session执行自定义Cypher查询时,结果仅包含直接查询的节点,而不包含相关节点(结果节点中的关系为null对象). IE.这些查询的深度似乎是0,而不是1,正如我从文档中所期望的那样.

When executing a custom Cypher query either via Spring Data @Query annotation or directly via the Neo4j Session, the result contains only the nodes directly queried for and not the related nodes (relationships are null in the resulting node objects). I.e. the depth for these queries seems to be 0 and not 1, as I would have expected from the docs.

如何通过OGM或深度为1的Spring Data Neo4j执行自定义Cypher查询?

How can I execute a custom Cypher query via OGM or Spring Data Neo4j that has depth 1?

推荐答案

默认深度1表示存储库和派生的查找器中的findOne/findAll/..方法.

The default depth 1 refers to findOne/findAll/.. methods from the repository and derived finders.

这是文档中有关自定义查询的内容:

This is what the documentation says about custom queries:

在当前版本中,自定义查询不支持分页,排序或自定义深度.此外,它不支持将路径映射到域实体,因此,不应从Cypher查询中返回路径.而是返回节点和关系,以使其映射到域实体.

In the current version, custom queries do not support paging, sorting or a custom depth. In addition, it does not support mapping a path to domain entities, as such, a path should not be returned from a Cypher query. Instead, return nodes and relationships to have them mapped to domain entities.

例如,当您进行查询时

MATCH (n:MyLabel)-[r]-(n2)
WHERE ... // some condition
RETURN n,r,n2

在RETURN子句中列出要映射到对象的所有节点/关系.

list all nodes/relationships you want to map to your objects in the RETURN clause.

这篇关于使用OGM在自定义Cypher查询中的深度始终为0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆