Neo4j 简单关系不是使用 SDN/Spring Data 创建的

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

我在使用 SDN 在 NEO4J Db 中创建关系时遇到问题。 附加节点已创建,只是缺少关系。

聚合根服务

@Node("Service")
@Data(staticConstructor = "of")
public final class ServiceEntity {

  @Id
  private final Long id;
  private final String name;

  @Relationship(type = "handles", direction = INCOMING)
  private final AuthorityEntity authority;

  @Relationship("gives")
  private final ArtifactEntity output;

  @Relationship(value = "needs", direction = INCOMING)
  private final Collection<ArtifactEntity> input;
}

神器

@Node("Artifact")
@Data(staticConstructor = "of")
public class ArtifactEntity {

  @Id
  private final Long id;
  private final String name;
}

权威

@Node("Authority")
@Data(staticConstructor = "of")
public class AuthorityEntity {

  @Id
  private final String name;
}

Neo4j存储库

public interface ServiceSpringRepository extends Neo4jRepository<ServiceEntity, Long> {

}

每当我保存一些服务时,它都会创建所有附加的服务、工件和权限节点,但没有任何关系。

match(n) return n

的视图如下所示

对于

match(n)-[r]->(m) return n,r,m
我没有得到任何记录。

数据库概述如下所示:

java spring-boot neo4j spring-data-neo4j
1个回答
0
投票

任何@Node必须有一个有效的@Id才能建立关系。像这样重构你的代码:

@Node("Authority")
@Data(staticConstructor = "of")
public class AuthorityEntity {

  @Id
  @Generated
  private final String name;
}
© www.soinside.com 2019 - 2024. All rights reserved.