neo4j-三个节点之间的关系 [英] neo4j - Relationship between three nodes

查看:1132
本文介绍了neo4j-三个节点之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Neo4j完全陌生,现在正在对其进行测试. 我遇到的一个问题是如何使用Spring Data正确实现涉及3个不同节点的关系.例如,假设我有3个@NodeEntity:UserTagTaggableObject.

I'm totally new to Neo4j and I'm testing it in these days. One issue I have with it is how to correctly implement a relationship which involves 3 different nodes using Spring Data. Suppose, for example, that I have 3 @NodeEntitys: User, Tag and TaggableObject.

您可以说,User可以将Tag添加到TaggableObject;我用@RelationshipEntity TaggingOperation对该操作建模. 但是,我找不到胶合关系中3个实体的简单方法.我的意思是,显而易见的选择是设置@StartNode User tagger@EndNode TaggedObject taggedObject.但是如何将Tag添加到关系中?

As you can argue, a User can add a Tag to a TaggableObject; I model this operation with a @RelationshipEntity TaggingOperation. However, I can't find a simple way to glue the 3 entities inside the relationship. I mean, the obvious choice is to set @StartNode User tagger and @EndNode TaggedObject taggedObject; but how can I also add the Tag to the relationship?

推荐答案

我相信,这被称为"hyperedge",它不是Neo4j直接支持的.您可以创建一个额外的节点来支持它.因此,您可以拥有一个具有如下架构的TagEvent节点:

This is called a "hyperedge", I believe, and it's not something that Neo4j supports directly. You can create an additional node to support it, tough. So you could have a TagEvent node with a schema like so:

(:User)-[:PERFORMED]->(:TagEvent)
(:Tag)<-[:USED]-(:TagEvent)
(:TagObject)<-[:TAGGED]-(:TagEvent)

另一种选择是将外键存储为关系或节点上的属性.显然,这不是很简单,但是如果您仅需要它作为参考,则可能不是一个好的解决方案.请记住不要像在将来的版本中那样使用内部Neo4j ID,因为它可能并不可靠.为此,您应该创建自己的ID.

Another alternative is to store a foreign key as a property on a relationship or a node. Obviously that's not very graphy, but if you just need it for reference that might not be a bad solution. Just remember to not use the internal Neo4j ID as in future versions that may not be dependable. You should create your own ID for this purpose.

这篇关于neo4j-三个节点之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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