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

查看:26
本文介绍了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.

如何通过深度为 1 的 OGM 或 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.

http://docs.spring.io/spring-data/data-neo4j/docs/current/reference/html/#reference:session:loading-entities:cypher-queries

例如当您有查询时

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天全站免登陆