Skip to content

Commit 4c3cb13

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
NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [org.openmrs.Patient#] - TRUNK-3728
1 parent 83febc7 commit 4c3cb13

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
@@ -166,6 +166,13 @@ private void insertPatientStubIfNeeded(Patient patient) {
166166
}
167167
}
168168
}
169+
170+
//Without evicting person, you will get this error when promoting person to patient
171+
//org.hibernate.NonUniqueObjectException: a different object with the same identifier
172+
//value was already associated with the session: [org.openmrs.Patient#]
173+
//see TRUNK-3728
174+
Person person = (Person) sessionFactory.getCurrentSession().get(Person.class, patient.getPersonId());
175+
sessionFactory.getCurrentSession().evict(person);
169176
}
170177

171178
// 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
@@ -2260,4 +2260,22 @@ public void getPatientIdentifierTypes_shouldOrderAsDefaultComparator() throws Ex
22602260
Collections.sort(sortedList, new PatientIdentifierTypeDefaultComparator());
22612261
Assert.assertEquals(sortedList, list);
22622262
}
2263+
2264+
/**
2265+
* https://tickets.openmrs.org/browse/TRUNK-3728
2266+
*
2267+
* @see {@link PatientService#savePatient(Patient)}
2268+
*/
2269+
@Test
2270+
@Verifies(value = "should not throw NonUniqueObjectException when called with person promoted to patient", method = "savePatient(Patient)")
2271+
public void savePatient_shouldNotThrowNonUniqueObjectExceptionWhenCalledWithPersonPromotedToPatient() throws Exception {
2272+
Person person = personService.getPerson(1);
2273+
Patient patient = patientService.getPatientOrPromotePerson(person.getPersonId());
2274+
PatientIdentifier patientIdentifier = new PatientIdentifier("some identifier", new PatientIdentifierType(2),
2275+
new Location(1));
2276+
patientIdentifier.setPreferred(true);
2277+
patient.addIdentifier(patientIdentifier);
2278+
2279+
patientService.savePatient(patient);
2280+
}
22632281
}

0 commit comments

Comments
 (0)
Please sign in to comment.