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

问题描述 投票:0回答:1

我正在使用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个回答
0
投票

这是我来的最近的:

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

© www.soinside.com 2019 - 2024. All rights reserved.