如何在spring数据neo4j中建立这种关系的模型? [英] How to modeling this relation in spring data neo4j?

查看:287
本文介绍了如何在spring数据neo4j中建立这种关系的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于我有两个实体:公司,它们之间存在多种关系:

Given I have two entity: Person and Company, and there are multiple relationships between them:

人员-公司:

  1. 该人可以是公司的员工
  2. 该人可以是公司的股东
  3. 该人可以是公司的法人

公司-公司:

  1. 公司可以是公司的合法公司
  2. 公司可以是公司的股东

那么如何在spring数据neo4j中对此建模呢?

So how to modeling this in spring data neo4j?

我尝试建立3种关系类型:EMPLOY,INVEST,LEGAL,每种关系类型均以Company作为StartNode,以person作为EndNode,然后在company and person中,保持这些关系为"UNDIRECTED"方向,与当前图表相同,但是在保存和搜索时始终会出现stackoverflow错误.

What I tried is make 3 relationship types: EMPLOY, INVEST, LEGAL, each relationship type with the Company as the StartNode and the person as the EndNode, then in company and person, keep these relationships with the "UNDIRECTED" direction, just same as the diagram present, but always get the stackoverflow error when saving and searching.

推荐答案

是的,现在这是 github ,所有类都放在sample.spring.data.neo4j包中,并进行相应的测试sample.spring.data.neo4j.repositories.CompanyRepositoryTest

Yes, now here is the solution in github, all the classes are house in sample.spring.data.neo4j package, and the the corresponding test sample.spring.data.neo4j.repositories.CompanyRepositoryTest

一开始的大问题是,它总是抛出 StackOverFlow 异常,这是 lombok 批注引起的,在删除所有lombok批注并使用普通的getter/之后,二传手,一切顺利.

The big issue at the beginning is it always throws the StackOverFlow exception which is due the the lombok annotation, after remove all the lombok annotations and use the plain getter/setter, everything goes well.

这篇关于如何在spring数据neo4j中建立这种关系的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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