Remove manual id management in child entities

This is reverting a workaround for a Hibernate "feature". There's
no need for the child entities (Pet and Visit) to know about their
parent (foreign key). Hibernate can manage that just fine with a
@JoinColumn. But it needs a nullable foreign key column in the
DB schema. That's the downside. The upside is much less code in
Java.
This commit is contained in:
Dave Syer 2022-01-06 11:18:15 +00:00
parent 43beff91a3
commit b559077f14
10 changed files with 25 additions and 60 deletions

View file

@ -75,11 +75,11 @@ class OwnerControllerTests {
Pet max = new Pet();
PetType dog = new PetType();
dog.setName("dog");
max.setId(1);
max.setType(dog);
max.setName("Max");
max.setBirthDate(LocalDate.now());
george.setPetsInternal(Collections.singleton(max));
george.addPet(max);
max.setId(1);
return george;
};
@ -95,7 +95,6 @@ class OwnerControllerTests {
given(this.owners.findById(TEST_OWNER_ID)).willReturn(george);
Visit visit = new Visit();
visit.setDate(LocalDate.now());
visit.setPetId(george.getPet("Max").getId());
george.getPet("Max").getVisits().add(visit);
}

View file

@ -216,7 +216,6 @@ class ClinicServiceTests {
assertThat(visits).hasSize(2);
Visit[] visitArr = visits.toArray(new Visit[visits.size()]);
assertThat(visitArr[0].getDate()).isNotNull();
assertThat(visitArr[0].getPetId()).isEqualTo(7);
}
}