Troubleshooting Exceptions



You must do all work on API objects within a transaction (or "unit of work"). This is because we use hibernate lazy loading of the names/addresses/attributes/identifiers of patients/persons, the sets and answers of concepts, etc. When you call say, getIdentifiers(), in the background Hibernate is actually going to the database and fetching the identifiers for that patient. If your transaction has been closed, Hibernate no longer has a connection to the database – giving you a LazyInitializationException.

If you know you need to access a patient's identifiers outside of your unit of work, you need to initialize that list of objects. You can do this by just calling size() on each list. e.g. patient.getIdentifiers().size();// start unit of work
Openmrs.openSession(); // done automatically in webapp at start of page rendering by OpenmrsFilter

Patient patient = Context.getPatientService.getPatient(101);
List<PersonAttribute> attrs = patient.getPersonAttributes();
... attrs.get(0);

//end unit of work
Openmrs.closeSession(); // done automatically in webapp at end of page rendering by OpenmrsFilter



NOTE: This exception occurs when deploying a module that has been compiled with a version of the JDK that is newer than the version of the JRE running OpenMRS. java.lang.UnsupportedClassVersionError.

Bad version number in .class file

java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass($100($ Method)

Solution: Make sure the JDK version that is used to compile the code is older than (or the same as) the JRE version that is used to execute the code. For development environments, where the code is compiled and deployed on the same machine, this should not be an issue.

However, if you're compiling on one machine and deploying on another machine, make sure that the Java version on the Build machine is older than (or the same as) the version on the Runtime machine. Note: This exception is still under investigation.[edit]

NOTE: resources.openmrs.orgProblemWhen working offline, your module will not build saying is an unknown host. This url is defined as the dtd in the config.xml file.


  1. Put the config-1.0.dtd document in the lib-common folder in your module

  2. In the inittarget your module's build.xml file, replace: <xmlproperty file="metadata/config.xml" />
    with this: <xmlcatalog id="common-dtds">
    <dtd publicId="-//OpenMRS//DTD OpenMRS Config 1.0//EN" location="lib-common/config-1.0.dtd"/>
    <xmlproperty file="metadata/config.xml" >
    <xmlcatalog refid="common-dtds"/>
    </xmlproperty> Retrieved from ""