Spring Data Neo4j 使用@RelationshipProperties 和@TargetNode 实现关系实体

Spring Data Neo4j implement relationship entity with @RelationshipProperties and @TargetNode

我有以下遗留关系实体,我想使用 @RelationshipProperties@TargetNode 升级到最新的 SDN:

@RelationshipEntity(type = "HAS_VALUE_ON")
public class RelationshipValue {

    @Id
    @GeneratedValue
    private Long graphId;

    @StartNode
    private Decision decision;

    @EndNode
    private Characteristic characteristic;

能否请您展示如何使用 @RelationshipProperties@TargetNode 注释实现它?

与属性的关系不再指向两个实体,而是一种定向关系。我们不做任何假设 TargetNode 是结束节点还是开始节点。这是在关系定义 class 中定义的。 假设在决策中使用了 RelationshipValue 并且它应该连接到 Characteristic,您可以定义如下内容:

@RelationshipProperties
public class RelationshipValue {

    @Id
    @GeneratedValue
    private Long graphId;

    @TargetNode
    private Characteristic characteristic;

并在 Decision

public class Decision {

    @Relationship("HAS_VALUE_ON") // direction can be OUTGOING (default) or INCOMING
    private RelationshipValue relationshipValue;
}

x-post: https://community.neo4j.com/t/spring-data-neo4j-implement-relationship-entity-with-relationshipproperties-and-targetnode/38429/2?u=gerrit.meier