dpkass
dpkass

Reputation: 88

Neo4j simple Relationships not created with SDN/Spring Data

I have problems with creating relationships in a NEO4J Db with SDN. The attached nodes are created, just the relationships are missing.

Aggregate Root Service

@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;
}

Artifact

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

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

Authority

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

  @Id
  private final String name;
}

Neo4jRepository

public interface ServiceSpringRepository extends Neo4jRepository<ServiceEntity, Long> {

}

Whenever I save some Services it will create all the attached Service, Artifact and Authority nodes, but without any relationships. The view looks like as follows for match(n) return n

Database state for example data

For match(n)-[r]->(m) return n,r,m I get no records.

The Database Overview looks like this:

Database Overview

Upvotes: 0

Views: 259

Answers (1)

Sherum
Sherum

Reputation: 69

Any @Node must have a valid @Id to have a relationship. Refactor your code like this:

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

  @Id
  @Generated
  private final String name;
}

Upvotes: 1

Related Questions