Skip to content
Snippets Groups Projects
Commit 5bf31dbe authored by Mic's avatar Mic
Browse files

fixed JPA issue when updating existing owners/pets

parent e3088715
No related branches found
No related tags found
No related merge requests found
...@@ -70,7 +70,12 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository { ...@@ -70,7 +70,12 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
@Override @Override
public void save(Owner owner) { public void save(Owner owner) {
this.em.persist(owner); if (owner.getId() == null) {
this.em.persist(owner);
}
else {
this.em.merge(owner);
}
} }
......
...@@ -53,7 +53,12 @@ public class JpaPetRepositoryImpl implements PetRepository { ...@@ -53,7 +53,12 @@ public class JpaPetRepositoryImpl implements PetRepository {
@Override @Override
public void save(Pet pet) { public void save(Pet pet) {
this.em.persist(pet); if (pet.getId() == null) {
this.em.persist(pet);
}
else {
this.em.merge(pet);
}
} }
} }
...@@ -45,7 +45,12 @@ public class JpaVisitRepositoryImpl implements VisitRepository { ...@@ -45,7 +45,12 @@ public class JpaVisitRepositoryImpl implements VisitRepository {
@Override @Override
public void save(Visit visit) { public void save(Visit visit) {
this.em.persist(visit); if (visit.getId() == null) {
this.em.persist(visit);
}
else {
this.em.merge(visit);
}
} }
......
...@@ -89,8 +89,8 @@ public abstract class AbstractClinicServiceTests { ...@@ -89,8 +89,8 @@ public abstract class AbstractClinicServiceTests {
owner.setCity("Wollongong"); owner.setCity("Wollongong");
owner.setTelephone("4444444444"); owner.setTelephone("4444444444");
this.clinicService.saveOwner(owner); this.clinicService.saveOwner(owner);
Assert.assertNotEquals("Owner Id should have been generated", owner.getId().longValue(), 0);
owners = this.clinicService.findOwnerByLastName("Schultz"); 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()); assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size());
} }
......
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