Good afternoon, I have an information system with a DB in Mysql. The connection with her and the mapping was made with Spring.
I am creating the services and I have a very important question. I put in context, I have two Ranger Entities and Curriculum, with a 1: 1 bidirectional relationship. When I delete an instance of Curriculum in the DB, I verify that this instance does not exist, however the Ranger curriculum attribute has not been set to null, but it still has the previously deleted curriculum. Should not spring do it on its own? Do I have to manually do a ranger.setCurriculum = null?
I leave the delete code:
public void delete(final Curriculum curriculum) {
Ranger principal;
Curriculum result;
Assert.isTrue(curriculum.getId() != 0);
principal = this.rangerService.findByPrincipal();
Assert.notNull(principal);
result = this.findCurriculumByPrincipal();
Assert.notNull(result);
Assert.isTrue(curriculum.equals(result));
this.curriculumRepository.delete(curriculum);
principal.setCV(null);
}
The findCurriculumByPrincipal takes the curriculum of the logged Ranger from the DB. I know that maybe it is not enough information but it is a conceptual doubt, I want to know if spring clears the Ranger FK when deleting the Curriculum
I have done a test with JUnit for the delete that succeeds when in the delete method I put the principal.setCV () = null;
@Test
public void testDeleteCurriculumOfPrincipal() {
Curriculum result;
super.authenticate("ranger1");
result = this.curriculumService.findCurriculumByPrincipal();
Assert.notNull(result);
this.curriculumService.delete(result);
result = this.curriculumService.findCurriculumByPrincipal();
Assert.isNull(result);
super.unauthenticate();
}