Hibernate Entity Resolution Failure Between IPD and MedicationAdministration Modules

The Bahmni team is currently working on migrating OpenMRS core, migration from the current 2.5.14 to v2.6.15. As part of this ongoing migration, we are facing issues with one of our custom modules - openmrs-module-ipd, a module that was working as expected on OMRS 2.5.15 but not on OMRS 2.6.14. Below is the exact error that we encountered -

openmrs-1  | WARN - AbstractApplicationContext.refresh(591) |2025-09-30T12:29:05,284| Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'procedureOrderExport' defined in URL [jar:file:/openmrs/data/.openmrs-lib-cache/fhir2Extension/lib/fhir2Extension-api-1.4.0-SNAPSHOT.jar!/org/openmrs/module/fhirExtension/export/impl/ProcedureOrderExport.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderServiceTarget' defined in class path resource [applicationContext-service.xml]: Cannot resolve reference to bean 'orderDAO' while setting bean property 'orderDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderDAO' defined in class path resource [applicationContext-service.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext-service.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: @OneToOne or @ManyToOne on org.openmrs.module.ipd.api.model.Slot.medicationAdministration references an unknown entity: org.openmrs.module.ipd.api.model.MedicationAdministration.

The openmrs-module-ipd module was introduced to support In-Patient Department (IPD) functionality. Within this module, the Slot class (api/src/main/java/org/openmrs/module/ipd/api/model/Slot.java) represents a scheduled time window for administering medication to an inpatient. Each Slot maintains a reference to a MedicationAdministration record—whenever a medication is administered during a slot, a corresponding MedicationAdministration entry is created and linked to it.

Our initial hypothesis was that in openmrs-module-ipd, the Slot model does not explicitly import MedicationAdministration. Since both classes—Slot (in IPD) and MedicationAdministration—share the same package name, Hibernate may have previously resolved the mapping implicitly. However, in newer versions, Hibernate’s entity resolution appears to be stricter, and it can no longer infer this relationship automatically.

Attempts So Far

  1. We updated the package name and fixed the imports accordingly (changes here), but the issue persisted.

  2. We then added explicit Hibernate mappings using .hbm files, but this also did not resolve the problem.

  3. The only way we’ve been able to get the module to start successfully is by removing the @OneToOne mapping between MedicationAdministration and Slot. While this allows the module (except SNOMED) to load, it breaks the intended medication administration linkage and functionality.

At this point, we’ve exhausted most of the solutions we could think of. We suspect there’s a subtle issue we’re overlooking—possibly related to how entities are being scanned or loaded between modules—but haven’t been able to pinpoint it yet.

We would greatly appreciate any insights, suggestions, or guidance from the community to help us resolve this. If anyone has encountered similar Hibernate entity resolution issues across modules—or has suggestions on alternate mapping strategies—please do share your thoughts.

cc: @ibacher, @dkayiwa, @grace, @raff, @burke, @binduak, @kavitha11, @r.kalai, @angshuonline, @mohant

Can you try the changes in these two pull requests and see if the problem is fixed?

1 Like

@rahul can you try the above changes suggested by Daniel?

Thanks @dkayiwa, for pitching in. With the proposed changes, the error now appears slightly different from what we encountered earlier, but the underlying issue still persists.

WARN - AbstractApplicationContext.refresh(591) |2025-10-13T16:33:57,914| Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'procedureOrderExport' defined in URL [jar:file:/openmrs/data/.openmrs-lib-cache/fhir2Extension/lib/fhir2Extension-api-1.4.0-SNAPSHOT.jar!/org/openmrs/module/fhirExtension/export/impl/ProcedureOrderExport.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderServiceTarget' defined in class path resource [applicationContext-service.xml]: Cannot resolve reference to bean 'orderDAO' while setting bean property 'orderDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderDAO' defined in class path resource [applicationContext-service.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext-service.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/openmrs/module/ipd/api/model/MedicationAdministration

While initializing sessionFactory, Hibernate hit a NoClassDefFoundError for:

org.openmrs.module.ipd.api.model.MedicationAdministration

That said, medication-administration is marked as a required module and should ideally be loaded before ipd.

@rahu1ramesh is it possible to get the full openmrs server side log?

I have just run openmrs 2.5.14 with the modules produced by the latest snapshot version of bahmni distro. The only module that i changed was medicationadministration by removing this changeset which was complaining about a missing database view. Which i assumed was caused by my not having configured bahmni as i should. I only wanted to check if the emr modules can start.

All was well. Then i upgraded to openmrs 2.6.15 and i am still able to have all the bahmni modules started and running without any errors.

Do i need to do more, in addition to the above simple steps, in order to reproduce the reported problem?

FWIW, i am running openmrs-core with mvn jetty:run and mvn cargo:run

Hey @dkayiwa

In our case, we weren’t able to bring up some of the modules, so we had to bump the versions of openmrs-core and emrapi (since several resources had been deprecated) to get the core modules—bahmni-core and fhir2extension—running.

Could you try upgrading to OpenMRS 2.6.15 with the following changes and see if you’re able to get bahmni-ipd up without errors?

  1. bahmni-core #285
  2. openmrs-module-medicationadministration #11
  3. openmrs-module-fhir2Extension #75

Thanks again for taking the time to look into this — really appreciate your help.

After the proposed changes, here’s the truncated log with the relevant error logs-> openmrs-logs.txt (433.3 KB)

What i get with the above three is a different error which looks related to the bahnmni core pull request changes. WARN - AbstractApplicationContext.refresh(591) |2025-10-14T12:46:45,274| Excepti - Pastebin.com

Hey @dkayiwa,

Apologies for the confusion earlier. Could you please take a pull of the latest snapshot version of the Bahmni/openmrs-distro-bahmni and try once again?

We realized that a module version bump was missed in the earlier PR for bahmni-core, which was likely causing this issue. The latest snapshot should have the fix in place.

Thanks again for your patience and continued help with this.

Hey @dkayiwa,

Just following up on this — whenever you get a chance, could you please try pulling the latest version of Bahmni/openmrs-distro-bahmni and try the proposed fix there?

Thanks again for your time and continued support!

With those changes, i am now not able to start the emr even on 2.5.14 as i get these errors: ERROR - Listener.performWebStartOfModules(670) |2025-10-21T08:31:12,769| Unable - Pastebin.com

Thanks, @dkayiwa, for helping with this issue.

I’m not sure what’s causing the discrepancy. In our environments (https://docker.standard.mybahmni.in/openmrs), with the latest changes, OpenMRS boots if we exclude the problematic bahmni-ipd module.

Could you please do a quick triage and confirm whether the installed module versions match the dependency versions specified here? https://github.com/Bahmni/openmrs-distro-bahmni/blob/master/distro/pom.xml#L17

Much appreciated.

cc: @binduak

Yes they do match. And the error java.lang.ClassNotFoundException: org.openmrs.module.emrapi.web.controller.ConditionController does not surprise me because i cannot even see that class here: openmrs-module-emrapi/omod/src/main/java/org/openmrs/module/emrapi/web/controller at 2.3.0 · openmrs/openmrs-module-emrapi · GitHub

2 Likes