Saving Obs with Boolean datatype throws LazyInitializationException. - OpenMRS 1.9.2

While saving Observation with Boolean Concept using REST APIs exception is thrown. We are using OpenMRS 1.9.2 and Web Rest Service 1.2

Based on the ticket RESTWS-529, I have applied patch provided by @dkayiwa for Saving Boolean values
Interestingly, After applying the patch I can save only True values and when Observation has False value, I get an Exception Full Back trace

LazyInitializationException: failed to lazily initialize a collection of role: org.openmrs.Concept.names

Observation is getting saved in Database but while converting the response object to JSON above exception is thrown and client receives 500 Internal Server Error message.

	"person": "9cd100f9-0c79-472f-a2cf-a3a31aae0a2a",
	"concept": "90bf08d5-52ef-4956-b714-e9f499aae274",
	"location": "8d6c993e-c2cc-11de-8d13-0010c6dffd0f",
	"encounter": "9abc8180-e8ea-4ed4-8210-c7652bfab67d",
	"obsDatetime": "2017-01-09T16:43:46.692+0530",
	"comment": "",
	"value": true

Thanks & Regards,

Can you try to reproduce this in a unit test?

Thanks @dkayiwa

Please find the Unit Test to reproduce this issue. I have added this test to file

diff --git a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/
index f4e6377..d81dc9e 100644
--- a/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/
+++ b/omod-1.9/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/
@@ -127,6 +127,12 @@ public class ObsResource1_9Test extends BaseDelegatingResourceTest<ObsResource1_
                rep = (SimpleObject) rep.get("value");
                Assert.assertEquals("coded", concept.getUuid(), rep.get("uuid"));
+               // boolean
+               obs.setConcept(Context.getConceptService().getConceptByUuid(BOOLEAN_CONCEPT_UUID));
+               ObsResource1_8.setValue(obs, true);
+               rep = getResource().asRepresentation(getObject(), Representation.DEFAULT);
+               Assert.assertEquals("boolean", true, rep.get("value"));
                // datetime
                Date datetime = new Date();
                clearAndSetValue(obs, ObsType.DATETIME, datetime);

@mani i mean a test which posts something like the values you have above to end up with the same LazyInitializationException

With the above test case I can reproduce same LazyInitializationException. From what I have debugged webservices module, Obs gets saved with true/false values, but problem arises when saved Observation object is converted to JSON String.

rep = getResource().asRepresentation(getObject(), Representation.DEFAULT);

LazyInitialization Exception is thrown when Object is converted to Default Representation. Backtrace of crash when I run test case in

Meanwhile, I am trying to find out how to POST a request from Unit Test case.

I was able to create TestCase with POST messages Here is the patch with test cases. Interestingly, Now Exception is not thrown while conversion of Obs to Default Representation. Can I assume that there is some problem with my installation and version of WebServices module ?

If that is the case Could you please give me some pointers to find out where the issue is in my version ?


Just for troubleshooting purposes, are you able to reproduce it if you replaced your module version with the latest release of the rest webservices module>

Thanks @dkayiwa

Yes I tried to replace our version with latest version of webservices module. But I get the following error.

Error while trying to start module Module requires at least version 1.9.10, Current code version is only ** org.openmrs.module.ModuleUtil.checkRequiredVersion( ** org.openmrs.module.ModuleFactory.startModuleInternal( ** org.openmrs.api.context.Daemon$

Is it possible to get this working with 1.9.2 version ?

The easier path would be an upgrade to 1.9.10 since it is a maintenance release and hence does not usually have database changes.

Thanks, I will try to upgrade OpenMRS to 1.9.10 and check.