[英]Spring-Data-Neo4j: relationshipEntity return only graphId for nodes.
I am creating an example using Spring-Data-Neo4j
. 我正在使用
Spring-Data-Neo4j
创建一个示例。 In this, perform CRUD operations, and all operation run successfully. 这样,执行CRUD操作,所有操作都将成功运行。 But when i fetch the relationa ship collection from entity, it return only
graphId
for nodes, and other values are null. 但是,当我从实体获取关系集时,它仅返回节点的
graphId
,其他值均为null。 Following is my code. 以下是我的代码。 If i do something wrong, please correct me.
如果我做错了,请纠正我。
Entities: 实体:
@NodeEntity
@ToString(callSuper=true, exclude={"movies"})
@EqualsAndHashCode(callSuper = true, exclude = {"name", "movies"})
public class Person extends BaseEntity{
@Getter @Setter
@Indexed(unique = true)
private Long id;
@Getter @Setter
private String name;
@Getter @Setter
@RelatedToVia(type = RelationshipTypes.FRIEND, elementClass = FriendsRelationship.class, direction = Direction.BOTH)
private Set<FriendsRelationship> friends;
}
@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;
}
Create Relationship: 建立关系:
public FriendsRelationship createRelationshipBetweenPersons(Person person, Person friend,
Class<FriendsRelationship> relationshipEntity, String friendshipType) {
FriendsRelationship relationship = neo4jTemplate.createRelationshipBetween(person, friend, relationshipEntity, friendshipType, true);
neo4jTemplate.save(relationship);
return relationship;
}
Controller: 控制器:
@RequestMapping(value="find-person-by-id", method=RequestMethod.POST)
public String findPersonById(long id, Model model) {
Person person = personService.findPersonByProperty("id", id);
model.addAttribute("actor", person);
model.addAttribute("personFriends", person.getFriends());
return "person/view-person-detail";
}
In controller, when i fetch the person, the person fetch successfully, but i fetch the friends, it contain start_node
with same person object, but end_node
contain person object with graphId
value only, others values are null. 在控制器中,当我获取人时,人获取成功,但是我获取朋友时,它包含具有相同人员对象的
start_node
,但end_node
包含具有graphId
值的人员对象,其他值均为null。
For solve this problem, we need to add @Fetch
annotation at start-node and end-node in FriendsRelationship
entity, like as below: 为了解决此问题,我们需要在
FriendsRelationship
实体的开始节点和结束节点处添加@Fetch
批注,如下所示:
@RelationshipEntity(type=RelationshipTypes.FRIEND)
public class FriendsRelationship extends BaseEntity{
@Fetch @StartNode
@Getter @Setter
private Person person;
@Fetch @EndNode
@Getter @Setter
private Person friend;
@Getter @Setter
private String friendsType;
}
Now the data fetch successfully. 现在,数据已成功获取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.