Hello,
I am trying to create a set of CRUD REST APIs for Neo4j. Everything works fine except I am unable to create a new relationship. These are the entities:
@Node("Movie")
@Getter @Setter @AllArgsConstructor @ToString
public class Movie {
@Id
@GeneratedValue
//@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Long id;
@Property("title")
private String title;
@Property("description")
private String description;
@Relationship(type = "ACTED_IN", direction = Relationship.Direction.INCOMING)
private List<Roles actorsAndRoles;
@Relationship(type = "DIRECTED", direction = Relationship.Direction.INCOMING)
private List<Person directors;
}
@Node("Person")
@Getter @Setter @AllArgsConstructor @ToString
public class Person {
@Id @GeneratedValue
private Long id;
@Property("name")
private String name;
@Property("born")
private String born;
}
@Getter @Setter @AllArgsConstructor @ToString
@RelationshipProperties
public class Roles{
@RelationshipId
private Long id;
@TargetNode
private Person person;
@Property("roles")
private List<String roles;
}
This is the controller (the class is called MovieController) method I am calling:
@PostMapping
public ResponseEntity create(@RequestBody Movie movie){
try {
movie.setId(null);
return ResponseEntity.ok(movieService.save(movie));
}
catch(Exception e){
return ResponseEntity.internalServerError().body(e.getMessage());
}
}
I have uploaded the code here: https://github.com/RosarioB/spring-boot-crud-rest-api-neo4j/tree/basic_crud
This is an example of a body of a POST request at: http://localhost:8080/api/movies
{
"title":"Matrix",
"description":"Science fiction",
"actorsAndRoles":[
{
"person":{
"name":"Keanu Reeves",
"born":"27-01-1963"
}
}
]
}
And this is the response:
{
"id": 16,
"title": "Matrix",
"description": "Science fiction",
"actorsAndRoles": [
{
"id": null,
"person": {
"id": 17,
"name": "Keanu Reeves",
"born": "27-01-1963"
},
"roles": null
}
],
"directors": null
}
Unfortunately on the database only the 2 nodes (one Person and one Movie) got created but not the relationship. I would have expected the relationship ACTED_IN to be created too.
What am I doing wrong? Thank you very much!