当我们使用CreateRelationsInterween时,如何在SpringDataNeo4j中向关系添加属性
例如,我想在用户A和用户B之间建立关系,他们有名为MakeFriend的RelationshipEntity,我在下面的代码中使用,但我还想在RelationEntity中设置一些属性值,如role=10当我们使用CreateRelationsInterween时,如何在SpringDataNeo4j中向关系添加属性,spring,neo4j,spring-data-neo4j,Spring,Neo4j,Spring Data Neo4j,例如,我想在用户A和用户B之间建立关系,他们有名为MakeFriend的RelationshipEntity,我在下面的代码中使用,但我还想在RelationEntity中设置一些属性值,如role=10 userRepository.createRelationshipBetween(startUser, endUser, MakeFriend.class, RelTypes.FRIEND.name()); @RelationshipEntity public class MakeFrien
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;
您可以将以下内容添加到UserEntity类中:
@RelatedToVia(type = RelTypes.FRIEND, direction = Direction.BOTH)
private MakeFriend friend;
friend.setRole("yourRole");
当您使用高级映射模式时,另一种方法是使用以下方法之一。然后将属性添加到返回的关系中
第三种方法是使用该方法并提供属性(如角色)作为最终参数。您可以将以下内容添加到UserEntity类中:
@RelatedToVia(type = RelTypes.FRIEND, direction = Direction.BOTH)
private MakeFriend friend;
friend.setRole("yourRole");
当您使用高级映射模式时,另一种方法是使用以下方法之一。然后将属性添加到返回的关系中
第三种方法是使用该方法并提供您的属性(例如角色)作为最后一个参数。还有一个单独的
relationshipGraphRespository
,如果您从该接口进行扩展,它会添加一些更有用的方法。另外还有一个单独的relationshipGraphRespository
,如果您从该接口进行扩展,它会添加一些更有用的方法