Skip to content

Fix Infinispan/Java 21+ startup failure by disabling Hibernate L2 cache#113

Merged
dkayiwa merged 1 commit intoopenmrs-emr3from
fix-java21-disable-l2-cache
Feb 28, 2026
Merged

Fix Infinispan/Java 21+ startup failure by disabling Hibernate L2 cache#113
dkayiwa merged 1 commit intoopenmrs-emr3from
fix-java21-disable-l2-cache

Conversation

@dkayiwa
Copy link
Member

@dkayiwa dkayiwa commented Feb 28, 2026

Problem

Infinispan 13.0.22 (bundled in OpenMRS Core 2.8.4) calls Subject.getSubject() during initialization, which throws UnsupportedOperationException on Java 21.0.4+ and is removed entirely in Java 24 (JEP 486).

Fix

Disable Hibernate L2 cache via hibernate.cache.use_second_level_cache=false in the runtime properties. OpenMRS's HibernateSessionFactoryBean merges runtime properties into Hibernate config, so this prevents Infinispan from ever initializing.

This is the simpler alternative to #112 (which patches the Infinispan WAR to keep L2 caching). For a standalone/demo distribution the performance impact is negligible.

Changes

  • src/main/config/openmrs-runtime.properties: Add hibernate.cache.use_second_level_cache=false
  • src/main/java/org/openmrs/standalone/Bootstrap.java: Sync default vm_arguments to include --add-opens=java.base/java.lang=ALL-UNNAMED

Compatibility

Works on Java 21, 24, 25, and all future versions (no dependency on Security Manager APIs).

@dkayiwa
Copy link
Member Author

dkayiwa commented Feb 28, 2026

@copilot remove .DS_Store

Copy link
Contributor

Copilot AI commented Feb 28, 2026

@dkayiwa I've opened a new pull request, #114, to work on those changes. Once the pull request is ready, I'll request review from you.

@dkayiwa dkayiwa force-pushed the fix-java21-disable-l2-cache branch 2 times, most recently from cfa113d to c1ab906 Compare February 28, 2026 21:14
Disable Hibernate L2 cache in openmrs-runtime.properties by setting
hibernate.cache.use_second_level_cache=false. This prevents Infinispan
from initializing, avoiding the Java 21+ incompatibility where
Subject.getSubject() throws UnsupportedOperationException (removed
entirely in Java 24 via JEP 486).

OpenMRS's HibernateSessionFactoryBean merges runtime properties into
the Hibernate config, so this single property prevents Infinispan's
InfinispanRegionFactory from ever being created.

For a standalone/demo distribution the L2 cache performance impact is
negligible. See PR #112 for an alternative approach that keeps L2
caching by patching the Infinispan WAR.

Also sync the Bootstrap.java default vm_arguments with the runtime
properties by adding the missing --add-opens flag.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dkayiwa dkayiwa force-pushed the fix-java21-disable-l2-cache branch from c1ab906 to 62e65a3 Compare February 28, 2026 21:14
@dkayiwa dkayiwa merged commit fb30d61 into openmrs-emr3 Feb 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants