0

我在想什么是使用Spring从json在Neo4j中创建图形的最佳方法。想象一下,我有一个简单NodeEntity人:从Json在春季构建Neo4J图形

@NodeEntity public class Person { 
    private Set<Person> friends; 
} 

我想从像JSON对象建立人与人之间的友谊的图表:

{ 
    persons: [ 
    {name:"Fritz", friend:["Hans"]}, 
    {name:"Hans", friends:["Fritz", "Georg"]}, 
    {name:"Georg", friends:["Hans"]} 
    ] 
} 

我可以使用Spring数据的REST API,以去将json直接序列化到节点实体和关系?

回答

1

好问题,过去我只是试着写SD-REST的单个实体,而不是有关系的实体。

我可能会编写自己的rest-controller并将JSON转换为正确的对象。

您也可以直接使用Cypher并将json根作为参数json传递给cypher。

UNWIND {json}.persons as person 
// MERGE = get-or-create 
MERGE (p:Person {name:person.name}) 
UNWIND person.friends as friend 
// because the friend can come earlier as friend than as a person 
MERGE (f:Person {name:friend.name}) 
// merge on relationship to make sure it only exists once, no matter the direction 
MERGE (p)-[:KNOWS]-(f) 

该查询可以是SDN存储库的一部分,也可以通过Neo4jTemplate或-Session调用。

在SDN4中,您可以使用直接从您的域对象创建的SDN4。

+0

我一般我都推荐检查一下SDN 4,它将在本周发布为RC1,这是一个从头开始对Neo4j Server进行了优化的完全重写,并清除了我们在SDN3中遇到的很多问题。 –