From ef68dce48faeea4d6a6c9e7b22d93e09e9e0821b Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Tue, 27 Aug 2024 14:29:11 -0400 Subject: [PATCH] WFLY-19664 Log warning if hibernate.cache.region.factory_class setting is ignored Signed-off-by: Scott Marlow --- .../org/jboss/as/jpa/hibernate/JpaLogger.java | 5 +++++ .../service/ServiceContributorImpl.java | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/jpa/hibernate6/src/main/java/org/jboss/as/jpa/hibernate/JpaLogger.java b/jpa/hibernate6/src/main/java/org/jboss/as/jpa/hibernate/JpaLogger.java index 2b8a3aa75799..a31b16121fa9 100644 --- a/jpa/hibernate6/src/main/java/org/jboss/as/jpa/hibernate/JpaLogger.java +++ b/jpa/hibernate6/src/main/java/org/jboss/as/jpa/hibernate/JpaLogger.java @@ -6,6 +6,7 @@ package org.jboss.as.jpa.hibernate; import static org.jboss.logging.Logger.Level.INFO; +import static org.jboss.logging.Logger.Level.WARN; import org.hibernate.boot.archive.spi.ArchiveException; import org.jboss.logging.BasicLogger; @@ -46,6 +47,10 @@ public interface JpaLogger extends BasicLogger { @Message(id = 20261, value = "Hibernate ORM did not register LifeCycleListener") IllegalStateException HibernateORMDidNotRegisterLifeCycleListener(); + @LogMessage(level = WARN) + @Message(id = 20262, value = "Application custom cache region setting is ignored %s=%s") + void ignoredCacheRegionSetting(String propertyName, String setting ); + /** * Creates an exception indicating application is setting persistence unit property "hibernate.id.new_generator_mappings" to * false which indicates that the old ID generator should be used, however Hibernate ORM 6 does not include the old ID generator. diff --git a/jpa/hibernate6/src/main/java/org/jboss/as/jpa/hibernate/service/ServiceContributorImpl.java b/jpa/hibernate6/src/main/java/org/jboss/as/jpa/hibernate/service/ServiceContributorImpl.java index 4f3f647aaa9c..a0f0c923bd03 100644 --- a/jpa/hibernate6/src/main/java/org/jboss/as/jpa/hibernate/service/ServiceContributorImpl.java +++ b/jpa/hibernate6/src/main/java/org/jboss/as/jpa/hibernate/service/ServiceContributorImpl.java @@ -41,10 +41,18 @@ public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) { final Object regionFactoryInitiatorEnabled = serviceRegistryBuilder.getSettings().getOrDefault(CONTROL2LCINTEGRATION, true); final Object regionFactory = serviceRegistryBuilder.getSettings().get(HIBERNATE_REGION_FACTORY_CLASS); - if ((regionFactory instanceof String) && ((String) regionFactory).contains(EHCACHE)) { - JPA_LOGGER.tracef("ServiceContributorImpl#contribute application is using Ehcache via regionFactory=%s", - regionFactory); - } else if (regionFactoryInitiatorEnabled == null || + if ((regionFactory instanceof String)) { + String cacheRegionFactory = (String) regionFactory; + if (cacheRegionFactory.contains(EHCACHE)) { + JPA_LOGGER.tracef("ServiceContributorImpl#contribute application is using Ehcache via %s=%s", + HIBERNATE_REGION_FACTORY_CLASS, cacheRegionFactory); + return; + } else { + // warn and ignore application cache region setting + JPA_LOGGER.ignoredCacheRegionSetting(HIBERNATE_REGION_FACTORY_CLASS, cacheRegionFactory); + } + } + if (regionFactoryInitiatorEnabled == null || (regionFactoryInitiatorEnabled instanceof Boolean && ((Boolean) regionFactoryInitiatorEnabled).booleanValue()) || Boolean.parseBoolean(regionFactoryInitiatorEnabled.toString())) { JPA_LOGGER.tracef("ServiceContributorImpl#contribute adding ORM initiator for 2lc region factory");