diff --git a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java index b58c1ba0059..6c37f057d17 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/PetController.java @@ -138,7 +138,7 @@ public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owne // checking if the pet name already exist for the owner if (StringUtils.hasText(petName)) { Pet existingPet = owner.getPet(petName.toLowerCase(), false); - if (existingPet != null && existingPet.getId().equals(pet.getId())) { + if (existingPet != null && !existingPet.getId().equals(pet.getId())) { result.rejectValue("name", "duplicate", "already exists"); } }