[英]How to add properties to the relationship in Spring data neo4j when we use createRelationshipBetween
For example I want to make relationship between User A and User B and they have RelationshipEntity named MakeFriend, I am used code below, but I am also want to set in relation entity some property values like role = 10......... 例如,我要在用户A和用户B之间建立关系,并且它们具有名为MakeFriend的RelationshipEntity,在下面使用我的代码,但是我也想在关系实体中设置一些属性值,例如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;
You could could add the following to your UserEntity class: 您可以将以下内容添加到UserEntity类:
@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. 使用高级映射模式时,另一种实现方法是使用NodeBacked.relateTo()方法之一。 Then add the property to the returned Relationship.
然后将该属性添加到返回的Relationship中。
And a third way, it to use the Neo4jTemplate.createRelationshipBetween() method and provide your properties (eg role) as the final argument. 第三种方法是,使用Neo4jTemplate.createRelationshipBetween()方法并提供属性(例如角色)作为最终参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.