我正在尝试为Neo4j创建一组CRUD REST API。一切都很好,除了我无法建立新的关系。这些实体是:
@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;
}
这是我调用的控制器(类称为MovieController)方法:
@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());
}
}
我在这里上传了代码:https://github.com/RosarioB/spring-boot-crud-rest-api-neo4j/tree/basic_crud
这是一个POST请求主体的示例,位于:http://localhost:8080/api/movies
{
"title":"Matrix",
"description":"Science fiction",
"actorsAndRoles":[
{
"person":{
"name":"Keanu Reeves",
"born":"27-01-1963"
}
}
]
}
这就是答案:
{
"id": 16,
"title": "Matrix",
"description": "Science fiction",
"actorsAndRoles": [
{
"id": null,
"person": {
"id": 17,
"name": "Keanu Reeves",
"born": "27-01-1963"
},
"roles": null
}
],
"directors": null
}
不幸的是,在数据库中只创建了2个节点(一个Person和一个Movie),而没有创建关系。我希望也能创建ACTED_IN关系。
我做错了什么?非常感谢!
1条答案
按热度按时间rhfm7lfc1#
这是Sping Boot 3.1.0和Spring Data Neo4j的已知问题。您可以将以下代码段添加到configuration/SpringBootApplication类。有关该问题的信息是here。一旦发布了更新版本,就应该修复它。