Help Needed: NoSuchTableException for Custom Table in Unit Tests (Java 21 / OpenMRS 2.8.0 Migration)

Context: I am working on migrating the Patient Flags Module to support Java 21 and OpenMRS 2.8.0. While the API logic is updated, I am stuck on a persistent NoSuchTableException during unit tests in the :patientflags-api module.

The Problem: When running FlagTest, all 12 tests fail with a DatabaseUnitRuntimeException caused by org.dbunit.dataset.NoSuchTableException: patientflags_flag. It appears the table is not being created in the H2 in-memory database before DBUnit attempts to load the XML dataset.

Technical Details:

  • Environment: Java 21, OpenMRS 2.8.0.
  • Test Class: Extends BaseModuleContextSensitiveTest.
  • Hibernate Mappings: Confirmed Flag.hbm.xml and others are in src/main/resources.
  • Test Configuration:
    • test-hibernate.cfg.xml includes hibernate.bytecode.provider=bytebuddy and hibernate.hbm2ddl.auto=update.
    • TestingApplicationContext.xml is configured to merge module mappings, though I have experimented with both overriding the sessionFactory and letting the core merge them.

What I have tried:

  1. Dataset Integrity: Fixed the XML dataset sequencing (ensuring Person precedes Patient and Metadata precedes Concepts).
  2. Java 21 Proxying: Added the ByteBuddy agent to the Maven Surefire configuration to handle proxying errors.
  3. DAO Layer: Updated HibernateFlagDAO to ensure it correctly interacts with the DbSessionFactory.

Error Snippet:

Plaintext[ERROR] FlagTest.initTestData:43->BaseContextSensitiveTest.executeDataSet:723 Caused by: org.dbunit.dataset.NoSuchTableException: patientflags_flag

PR Link for Reference: FLAG-87: Complete Configuration to Platform 2.8/Java 21 (Resolves All Compiler Issues) by Abhxay · Pull Request #104 · openmrs/openmrs-module-patientflags · GitHub

I would appreciate any guidance on why Hibernate 5 might be failing to generate the schema from module .hbm.xml files in this specific environment.

According to the build failures on your pull request, i see invalid target release: 21