diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java index 0a471b4d8..5a05b68fa 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java @@ -35,6 +35,7 @@ import org.springframework.samples.petclinic.model.Pet; import org.springframework.samples.petclinic.model.PetType; import org.springframework.samples.petclinic.model.Visit; import org.springframework.samples.petclinic.repository.OwnerRepository; +import org.springframework.samples.petclinic.util.EntityUtils; import org.springframework.stereotype.Repository; /** @@ -114,8 +115,10 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { params, new JdbcPetVisitExtractor() ); + Collection petTypes = getPetTypes(); for (JdbcPet pet : pets) { owner.addPet(pet); + pet.setType(EntityUtils.getById(petTypes, PetType.class, pet.getTypeId())); } } diff --git a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java index 428c285fd..7a902983f 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java @@ -69,6 +69,8 @@ public abstract class AbstractClinicServiceTests { Owner owner = this.clinicService.findOwnerById(1); assertThat(owner.getLastName()).startsWith("Franklin"); assertThat(owner.getPets().size()).isEqualTo(1); + assertThat(owner.getPets().get(0).getType()).isNotNull(); + assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat"); } @Test