diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java index dfa00ce3e1f33d4c1883b6c5b43019930afbdb4a..fd0f21763b2c2fd18745f5987ad0154ab9c4b003 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImpl.java @@ -70,7 +70,7 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository { @Override public void save(Owner owner) { - this.em.merge(owner); + this.em.persist(owner); } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java index ea185cc9b49b372e3597b4a0105879673d8047d9..4823aabc1492e6e8f7aa0ee945ec594d94b86cb6 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImpl.java @@ -53,7 +53,7 @@ public class JpaPetRepositoryImpl implements PetRepository { @Override public void save(Pet pet) { - this.em.merge(pet); + this.em.persist(pet); } } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java index 58d3709c7fcb09e54e7d7fec97ee07060efd0b42..fccf79533fd95edd7c44c521fd658a6402503208 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java @@ -45,7 +45,7 @@ public class JpaVisitRepositoryImpl implements VisitRepository { @Override public void save(Visit visit) { - this.em.merge(visit); + this.em.persist(visit); } 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 b29fb9462ea1b7e51db3f880e536588bd666743d..e3c5f0a5739588c539d5b7e05fec4b3d906d2df5 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java @@ -16,11 +16,13 @@ package org.springframework.samples.petclinic.service; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.Collection; import org.joda.time.DateTime; +import org.junit.Assert; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.samples.petclinic.model.Owner; @@ -88,6 +90,7 @@ public abstract class AbstractClinicServiceTests { owner.setTelephone("4444444444"); this.clinicService.saveOwner(owner); owners = this.clinicService.findOwnerByLastName("Schultz"); + assertNotNull("Owner Id should have been generated", owner.getId()); assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size()); } @@ -142,6 +145,7 @@ public abstract class AbstractClinicServiceTests { this.clinicService.saveOwner(owner6); owner6 = this.clinicService.findOwnerById(6); assertEquals(found + 1, owner6.getPets().size()); + assertNotNull("Pet Id should have been generated", pet.getId()); } @Test @@ -183,6 +187,7 @@ public abstract class AbstractClinicServiceTests { this.clinicService.savePet(pet7); pet7 = this.clinicService.findPetById(7); assertEquals(found + 1, pet7.getVisits().size()); + assertNotNull("Visit Id should have been generated", visit.getId()); }