我在使用 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
我没有得到任何记录。
数据库概述如下所示:
任何@Node必须有一个有效的@Id才能建立关系。像这样重构你的代码:
@Node("Authority")
@Data(staticConstructor = "of")
public class AuthorityEntity {
@Id
@Generated
private final String name;
}