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

5jdjgkvh  于 2023-04-06  发布在  Spring
关注(0)|答案(1)|浏览(1099)

我有以下旧关系实体,我想升级到最新的SDN @RelationshipProperties@TargetNode

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

    @Id
    @GeneratedValue
    private Long graphId;

    @StartNode
    private Decision decision;

    @EndNode
    private Characteristic characteristic;

你能展示一下如何用@RelationshipProperties@TargetNode注解实现它吗?

2hh7jdfx

2hh7jdfx1#

带有属性的关系不再指向两个实体,而是一个有向关系。我们不做任何假设,如果TargetNode是结束或开始节点。这是在关系定义类中定义的。
假设RelationshipValueDecision中使用,并且它应该连接到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

相关问题