Skip to content
Snippets Groups Projects
Commit 80159fa3 authored by Mic's avatar Mic
Browse files

fixed bug in JPA implementation: "save" methods were implemented using "merge" instead of "persist"

parent a9b0b474
No related branches found
No related tags found
No related merge requests found
......@@ -70,7 +70,7 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
@Override
public void save(Owner owner) {
this.em.merge(owner);
this.em.persist(owner);
}
......
......@@ -53,7 +53,7 @@ public class JpaPetRepositoryImpl implements PetRepository {
@Override
public void save(Pet pet) {
this.em.merge(pet);
this.em.persist(pet);
}
}
......@@ -45,7 +45,7 @@ public class JpaVisitRepositoryImpl implements VisitRepository {
@Override
public void save(Visit visit) {
this.em.merge(visit);
this.em.persist(visit);
}
......
......@@ -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());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment