{"record":{"id":"5703e7197820a875","repo":"quarkusio/quarkus","slug":"cache-region-cachename-object-count-and-m","errorCode":null,"errorMessage":"Cache region '${cacheName}': 'object-count' and 'maximum-weight' are mutually exclusive. Use 'object-count' for count-based eviction or 'maximum-weight' for weight-based eviction.","messagePattern":"Cache region '(.+?)': 'object-count' and 'maximum-weight' are mutually exclusive\\. Use 'object-count' for count-based eviction or 'maximum-weight' for weight-based eviction\\.","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/util/HibernateProcessorSupport.java","lineNumber":426,"sourceCode":"        } else {\n            p.put(AvailableSettings.USE_DIRECT_REFERENCE_CACHE_ENTRIES, Boolean.FALSE);\n            p.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, Boolean.FALSE);\n            p.put(AvailableSettings.USE_QUERY_CACHE, Boolean.FALSE);\n            p.put(AvailableSettings.JAKARTA_SHARED_CACHE_MODE, SharedCacheMode.NONE);\n        }\n    }\n\n    private static QuarkusPersistenceUnitCacheConfiguration toQuarkusCacheConfiguration(\n            HibernateOrmConfigPersistenceUnit config) {\n        Map<String, QuarkusPersistenceUnitCacheConfiguration.Cache> caches = new HashMap<>();\n        for (var regionEntry : config.cache().entrySet()) {\n            String cacheName = regionEntry.getKey();\n            var cacheConfig = regionEntry.getValue();\n            var memory = cacheConfig.memory();\n\n            // Validate mutual exclusivity\n            if (memory.objectCount().isPresent() && memory.maximumWeight().isPresent()) {\n                throw new IllegalStateException(\n                        \"Cache region '\" + cacheName + \"': 'object-count' and 'maximum-weight' are mutually exclusive. \"\n                                + \"Use 'object-count' for count-based eviction or 'maximum-weight' for weight-based eviction.\");\n            }\n            if (memory.weigherClass().isPresent() && memory.maximumWeight().isEmpty()) {\n                throw new IllegalStateException(\n                        \"Cache region '\" + cacheName + \"': 'weigher-class' requires 'maximum-weight' to be set.\");\n            }\n\n            caches.put(cacheName, new QuarkusPersistenceUnitCacheConfiguration.Cache(\n                    memory.objectCount().orElse(QuarkusPersistenceUnitCacheConfiguration.Cache.DEFAULT.maxSize()),\n                    cacheConfig.expiration().maxIdle()\n                            .orElse(QuarkusPersistenceUnitCacheConfiguration.Cache.DEFAULT.maxIdle()),\n                    memory.maximumWeight().orElse(-1L),\n                    memory.weigherClass().orElse(null)));\n        }\n        return new QuarkusPersistenceUnitCacheConfiguration(caches);\n    }\n","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/util/HibernateProcessorSupport.java#L408-L444","documentation":"When converting Hibernate second-level cache region config to Quarkus cache configuration, HibernateProcessorSupport validates that count-based eviction (object-count) and weight-based eviction (maximum-weight) are not both set for the same region; if both are present it throws IllegalStateException.","triggerScenarios":"toQuarkusCacheConfiguration (called from configureCaching) sees a cache region whose memory config has both quarkus.hibernate-orm.\"pu\".cache.\"<region>\".memory.object-count and .maximum-weight set.","commonSituations":"Copy-pasting cache tuning examples and leaving both options; migrating from object-count to maximum-weight without removing the old property; documenting both options in shared config templates.","solutions":["Remove one of the two properties: keep object-count for count-based eviction or maximum-weight for weight-based","If switching to weight-based eviction, also configure weigher-class when objects vary in size","Audit all cache regions in application.properties for this conflict"],"exampleFix":"// before\nquarkus.hibernate-orm.cache.\"com.acme.Foo\".memory.object-count=1000\nquarkus.hibernate-orm.cache.\"com.acme.Foo\".memory.maximum-weight=10MB\n// after\nquarkus.hibernate-orm.cache.\"com.acme.Foo\".memory.maximum-weight=10MB","handlingStrategy":"validation","validationCode":"// Fail fast in tests if both eviction styles are set for a region\nif (props.contains(\"quarkus.hibernate-orm.cache.X.memory.object-count\")\n && props.contains(\"quarkus.hibernate-orm.cache.X.memory.maximum-weight\"))\n    throw new IllegalStateException(\"object-count and maximum-weight are mutually exclusive\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose one eviction style per region and document it","Review cache config as part of PR checks","Keep cache tuning in one profile to avoid conflicting overrides"],"tags":["quarkus","hibernate-orm","caching","config-conflict"],"backgroundTag":"mutually-exclusive-config-options","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}