@Override public void save(Visit visit) { if (visit.getId() == null) { this.em.persist(visit); } else { this.em.merge(visit); } }
@Test @Transactional public void insertVisit() { Pet pet7 = this.clinicService.findPetById(7); int found = pet7.getVisits().size(); Visit visit = new Visit(); pet7.addVisit(visit); visit.setDescription("test"); // both storeVisit and storePet are necessary to cover all ORM tools this.clinicService.saveVisit(visit); this.clinicService.savePet(pet7); pet7 = this.clinicService.findPetById(7); assertEquals(found + 1, pet7.getVisits().size()); assertNotNull("Visit Id should have been generated", visit.getId()); }