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.