简体   繁体   中英

neo4j - Relationship between three nodes

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 @NodeEntity s: User , Tag and TaggableObject .

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?

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM