0

例如,我想在用户 A 和用户 B 之间建立关系,他们有名为 MakeFriend 的关系实体,我使用下面的代码,但我也想在关系实体中设置一些属性值,如角色 = 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;
4

1 回答 1

3

You could could add the following to your UserEntity class:

@RelatedToVia(type = RelTypes.FRIEND, direction = Direction.BOTH)
private MakeFriend friend;

friend.setRole("yourRole");

Another way to do it, when you're using the advanced mapping mode, is using one of the NodeBacked.relateTo() methods. Then add the property to the returned Relationship.

And a third way, it to use the Neo4jTemplate.createRelationshipBetween() method and provide your properties (e.g. role) as the final argument.

于 2013-03-26T12:49:04.693 回答