0

I am new to Neo4J and working with Spring data repository. Following is the domain definition

@NodeEntity
public class Actor {
    Long id;
    private Set<Role> roles;
}

@RelationshipEntity(type="PLAYED_IN")
public class Role {
    @GraphId   private Long relationshipId;
    @Property  private String title;
    @StartNode private Actor actor;
    @EndNode   private Movie movie;
}

@NodeEntity
public class Movie {
    private Long id;
    private String title;
}

And have GraphRepository defined for each entity class Following code does not save the RelationshipEntity

Actor actor = new Actor("actorName");
actor = actorRepository.save(actor);

Movie movie = new Movie("movieTitle");
movie = movieRepository.save(movie);

Role role = new Role(actor, movie, "roleTitle");
role = roleRepository.save(role);

Do I have to annotate the roles variable in Actor class?
Do I have to populate roles collection before saving Actor? If I do so then the properties on Role are not saved.

Luanne
  • 19,145
  • 1
  • 39
  • 51
sidgate
  • 14,650
  • 11
  • 68
  • 119

1 Answers1

1

Yes, you must annotate the roles in the Actor entity.

If you're using neo4j-ogm 1.1.3 or an earlier version, make sure that when you create the new role, you add this to the collection of roles in the Actor entity.

If you're using neo4j-ogm 1.1.4-SNAPSHOT, your code should work (after you annotate the roles)

Luanne
  • 19,145
  • 1
  • 39
  • 51