0
Hey, guys, how’s it going? I have a code for a Rest API that registers courses and students. There is a bi-directional relationship. N Students -> 1 Course mapped as follows:
@ManyToOne
@JoinColumn(name = "curso_id")
private Curso curso;
1 course -> N Students mapped as follows:
@OneToMany
@JoinColumn(name = "curso_id")
private List<Aluno> alunos = new ArrayList<>();
I am using an H2 database in the application to persist the data, however, I feel that I am not able to make the request in the correct way when creating a student. Follow my student creation method:
@PostMapping("/aluno")
public void create(@RequestBody Aluno aluno){
alunoRepository.save(aluno);
}
Request json to create course(working properly):
{
"nome": "Nutrição",
"campus": "Campos Araguari"
}
Request json to create student(not working properly):`
{
"nome": "Fulaninho",
"matricula": "745896",
"curso_id": 1
}
I’ve been stuck for a while and honestly I’m not finding the problem. I have tried to pass within the student a course object with its respective Id, also does not work :(