Skip to content

Commit a9e1e60

Browse files
dkayiwawluyima
authored andcommittedMay 12, 2013
NonUniqueObjectException: a different object with the same identifier
value was already associated with the session: [org.openmrs.Patient#] - TRUNK-3728 Applying auto format changes - TRUNK-3728
1 parent 6aecd36 commit a9e1e60

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎api/src/main/java/org/openmrs/api/db/hibernate/HibernatePatientDAO.java

+7
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ private void insertPatientStubIfNeeded(Patient patient) {
177177
}
178178
}
179179
}
180+
181+
//Without evicting person, you will get this error when promoting person to patient
182+
//org.hibernate.NonUniqueObjectException: a different object with the same identifier
183+
//value was already associated with the session: [org.openmrs.Patient#]
184+
//see TRUNK-3728
185+
Person person = (Person) sessionFactory.getCurrentSession().get(Person.class, patient.getPersonId());
186+
sessionFactory.getCurrentSession().evict(person);
180187
}
181188

182189
// commenting this out to get the save patient as a user option to work correctly

‎api/src/test/java/org/openmrs/api/PatientServiceTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -3379,4 +3379,22 @@ public void savePatient_shouldNotSetAVoidedNameOrAddressOrIdentifierAsPreferred(
33793379
Assert.assertTrue(address.isPreferred());
33803380
}
33813381

3382+
/**
3383+
* https://tickets.openmrs.org/browse/TRUNK-3728
3384+
*
3385+
* @see {@link PatientService#savePatient(Patient)}
3386+
*/
3387+
@Test
3388+
@Verifies(value = "should not throw NonUniqueObjectException when called with person promoted to patient", method = "savePatient(Patient)")
3389+
public void savePatient_shouldNotThrowNonUniqueObjectExceptionWhenCalledWithPersonPromotedToPatient() throws Exception {
3390+
Person person = personService.getPerson(1);
3391+
Patient patient = patientService.getPatientOrPromotePerson(person.getPersonId());
3392+
PatientIdentifier patientIdentifier = new PatientIdentifier("some identifier", new PatientIdentifierType(2),
3393+
new Location(1));
3394+
patientIdentifier.setPreferred(true);
3395+
patient.addIdentifier(patientIdentifier);
3396+
3397+
patientService.savePatient(patient);
3398+
}
3399+
33823400
}

0 commit comments

Comments
 (0)
Please sign in to comment.