例如,我想在用户A和用户B之间建立关系,他们有RelationshipEntity名为MakeFriend,我使用下面的代码,但我也想在关系实体中设置一些属性值,如role = 10 .... .....
userRepository.createRelationshipBetween(startUser, endUser, MakeFriend.class, RelTypes.FRIEND.name());
@RelationshipEntity
public class MakeFriend {
@GraphId
private Long id;
private String role;
@StartNode
private UserEntity startUser;
@EndNode
private UserEntity endUser
@NodeEntity
public class UserEntity implements Serializable {
private static final long serialVersionUID = 1L;
public static final String FRIEND = "FRIEND";
public static final String JOYNED = "JOYNED";
@GraphId
private Long id;
@Indexed(unique = true)
private Long userId;
private String email;
答案 0 :(得分:3)
您可以将以下内容添加到UserEntity类:
@RelatedToVia(type = RelTypes.FRIEND, direction = Direction.BOTH)
private MakeFriend friend;
friend.setRole("yourRole");
当您使用高级映射模式时,另一种方法是使用NodeBacked.relateTo()方法之一。然后将该属性添加到返回的Relationship。
第三种方法是使用Neo4jTemplate.createRelationshipBetween()方法并提供属性(例如角色)作为最终参数。