如何使用 Spring、OGM 和 @RelationshipEntity 合并 neo4j 中的两个现有节点

How to merge two existing nodes in neo4j using Spring, OGM and @RelationshipEntity

我正在使用 Spring neo4j ogm 并且我已经将实体保存在数据库中。现在我想用 spring ogm 在它们之间建立新的关系。问题是此时我只有实体 uuid,我想转义 getEntityByUuid() ,它可以获得实体对象,然后 repo.save() 就可以了。

如果我需要创建自定义查询,它能否以这种格式存在于存储库中:

public interface EntityRepository extends Neo4jRepository<Entity, Long> {
    @Query("MATCH (e:Entity {uuid:[=11=]}), (e2:Entity{uuid:}) CREATE (e)-[:MENTION{relationshipProperties...}]->(e2)")
    boolean createRelationshipBetweenExistingEntities(String  entity1uuid, String  entity2uuid, RelationshipNeo4j rel);

这些是我的 类:

public abstract class AbstractEntity {
@Id
@GeneratedValue
private Long id;
}
@RelationshipEntity(type = "MENTION")
public class RelationshipNeo4j extends AbstractEntity {
@Property
protected String type;
@Property
protected LocalDate date;
@StartNode
protected Entity start;
@EndNode
protected Entity end;
}

@NodeEntity
public class Entity extends AbstractEntity {
protected String name;
@Index(unique = true)
protected String  uuid;
protected String wikiURL;
protected String  description;
@Relationship(type="MENTION")
protected List<RelationshipNeo4j> relationships;
}

这是我最近的一次:

@Query("MATCH (e:Entity {uuid:{entity1uuid}}), (e2:Entity{uuid:{entity2uuid}}) CREATE (e)-[r:MENTION{uuid:{relationshipUuid},type:{type},date:{date}}]->(e2) RETURN e,e2,r")
RelationshipNeo4j createRelationshipBetweenExistingEntities(String  entity1uuid, String  entity2uuid, String  relationshipUuid, String  type, String date);

我们不能向查询中插入非原始类型: https://markhneedham.com/blog/2017/12/01/neo4j-cypher-property-values-can-primitive-types-arrays-thereof/