gpt4 book ai didi

java - Spring-Data-Neo4j:无法使用 neo4jtempalte createRelationshipBetween)() 方法创建实体之间的关系

转载 作者:行者123 更新时间:2023-12-01 12:09:47 31 4
gpt4 key购买 nike

我使用 spring-data-neo4j 创建两个节点之间的关系,但该关系不持久。服务器没有抛出异常。当我获取节点时,其中有空值。我正在使用 Neo4jTemplate createRelationshipBetween() 方法。以下是我的代码:

关系实体:

@RelationshipEntity(type=RelationshipTypes.FRIEND)
public class FriendsRelationship extends BaseEntity{

@StartNode
@Getter @Setter
private Person person;
@EndNode
@Getter @Setter
private Person friend;
@Getter @Setter
private String friendsType;
}


public class CreateEntitiesRelationship {

@Autowired
private Neo4jTemplate neo4jTemplate;

-------------------------------

public FriendsRelationship createRelationshipBetweenPersons(Person person, Person friend,
Class<FriendsRelationship> relationshipEntity, String friendshipType) {
FriendsRelationship relationship = neo4jTemplate.createRelationshipBetween(person, friend, relationshipEntity, RelationshipTypes.FRIEND, false);
neo4jTemplate.save(relationship);
return relationship;
}
}

实际问题是什么,我无法弄清楚。我是 Neo4j 的新手。

最佳答案

试试这个代码:

 {
Person _person = neo4jTemplate.save(person);
Person _friend = neo4jTemplate.save(friend);
FriendsRelationship relationship = neo4jTemplate.createRelationshipBetween(_person, _friend, relationshipEntity, RelationshipTypes.FRIEND, false);
neo4jTemplate.save(relationship);//optional. saved by default
return relationship;
}

关于java - Spring-Data-Neo4j:无法使用 neo4jtempalte createRelationshipBetween)() 方法创建实体之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27334225/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com