通过Neo4j OGM映射任意关系 [英] Map arbitrary relations via Neo4j OGM
问题描述
Neo4j OGM支持通过@Convert
和CompositeAttributeConverter
映射到实体类的任意节点属性,但是关系部分呢?如何在@NodeEntity
中映射任意关系?
Neo4j OGM supports arbitrary node properties being mapped to entity classes via @Convert
and CompositeAttributeConverter
but what about the relation part? How would I map arbitrary relations in a @NodeEntity
?
我的数据模型中使用的实际属性和关系是可配置的,即在编译时未知.示例:配置指定标签A和B的节点,以及从A到B的关系,名称为REL_1.现在,当我查询标签A的节点时,我想在对应的结果节点实体中检索和映射关系.
The actual properties and relations being used in my data model are configurable, i.e. they are not known at compile time. Example: Configuration specifies nodes of label A and B and a relation from A to B named REL_1. Now when I am querying nodes of label A then I would like to retrieve and map the relations in the corresponding resulting node entity.
我试图根据配置来构建密码查询,但是我坚持要获取其末端节点应由OGM映射的关系.这是我简化的生成查询结构:
I tried to build cypher queries depending on the configuration but I am stuck at retrieving relations whose end node should be mapped by OGM. Here is my simplified generated query structure:
MATCH (n:A) RETURN n, [(n)-[rn:REL_1]-(n2) | [rn, n2]]
我也尝试过
MATCH (n:A) RETURN n, [[(n)-[rn:REL_1]-(n2) | [rn, n2]]]
与使用固定数据模型调用session.load
时由OGM生成的模式相同.但是,两个查询都不会在session.query
调用的结果中映射n2
.相反,返回的n2
类型是NodeModel
,但我不想自己映射它,因为OGM已经能够做到. 我的查询出了什么问题?还是这个错误?
which is the same pattern as is generated by OGM when calling session.load
with a fixed data model. However, both queries do not map n2
in the result of session.query
call. Instead the returned type for n2
is a NodeModel
but I don't want to map it myself because OGM is already capable to do it. What's wrong with my query? Or is this a bug?
注意:此查询可以解决问题,但感觉像是一个奇怪的解决方法.
Note: This query would do the trick but that feels like an odd workaround.
MATCH (n:A) RETURN n, [(n)-[rn:REL_1]-() | rn], [(n)-[:REL_1]-(n2) | n2]
我使用的是Neo4J 3.5和SGM Boot 2.2.2附带的OGM 3.2.3.
I am using Neo4J 3.5 with OGM 3.2.3 included via Sprint Boot 2.2.2.
推荐答案
这可能是由于这个更简单的Cypher查询对您有用吗?
Does this more straightforward Cypher query work for you?
MATCH (n:A)-[rn:REL_1]-(n2) RETURN n, COLLECT({rn: rn, n2: n2})
这篇关于通过Neo4j OGM映射任意关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!