Troubleshooting Exceptions

LazyInitializationExceptionProblem

Solution:

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

[edit]

UnsupportedClassVersionErrorProblem

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(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
java.net.URLClassLoader.access$100(URLClassLoader.java:56)
java.net.URLClassLoader$1.run(URLClassLoader.java:195)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(URLClassLoader.java:188)
org.openmrs.module.ModuleClassLoader.loadClass(ModuleClassLoader.java:367)
org.openmrs.module.ModuleClassLoader.loadClass(ModuleClassLoader.java:310)
java.lang.ClassLoader.loadClass(ClassLoader.java:251)
org.openmrs.module.Module.expandExtensionNames(Module.java:347)
org.openmrs.module.Module.getExtensions(Module.java:322)
org.openmrs.module.ModuleFactory.startModule(ModuleFactory.java:318)
org.openmrs.module.web.controller.ModuleListController.onSubmit(ModuleListController.java:116)



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]

java.net.UnknownHostException

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

Solution

  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"/>
    </xmlcatalog>
    <xmlproperty file="metadata/config.xml" >
    <xmlcatalog refid="common-dtds"/>
    </xmlproperty> Retrieved from "http://archive.openmrs.org/wiki/Troubleshooting_Exceptions"http://www.mediawiki.org/