【问题标题】:How to merge two existing nodes in neo4j using Spring, OGM and @RelationshipEntity如何使用 Spring、OGM 和 @RelationshipEntity 合并 neo4j 中的两个现有节点
【发布时间】:2020-04-09 16:52:24
【问题描述】:

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

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

public interface EntityRepository extends Neo4jRepository<Entity, Long> {
    @Query("MATCH (e:Entity {uuid:$0}), (e2:Entity{uuid:$1}) 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;
}

【问题讨论】:

    标签: spring spring-boot neo4j neo4j-ogm spring-repositories


    【解决方案1】:

    这是我最近的一次:

    @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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多