【发布时间】: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