quarkusio/quarkus · error · IllegalStateException

Cache region '${cacheName}': 'object-count' and 'maximum-wei

Error message

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.

What it means

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.

Source

Thrown at extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/util/HibernateProcessorSupport.java:426

        } else {
            p.put(AvailableSettings.USE_DIRECT_REFERENCE_CACHE_ENTRIES, Boolean.FALSE);
            p.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, Boolean.FALSE);
            p.put(AvailableSettings.USE_QUERY_CACHE, Boolean.FALSE);
            p.put(AvailableSettings.JAKARTA_SHARED_CACHE_MODE, SharedCacheMode.NONE);
        }
    }

    private static QuarkusPersistenceUnitCacheConfiguration toQuarkusCacheConfiguration(
            HibernateOrmConfigPersistenceUnit config) {
        Map<String, QuarkusPersistenceUnitCacheConfiguration.Cache> caches = new HashMap<>();
        for (var regionEntry : config.cache().entrySet()) {
            String cacheName = regionEntry.getKey();
            var cacheConfig = regionEntry.getValue();
            var memory = cacheConfig.memory();

            // Validate mutual exclusivity
            if (memory.objectCount().isPresent() && memory.maximumWeight().isPresent()) {
                throw new IllegalStateException(
                        "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.");
            }
            if (memory.weigherClass().isPresent() && memory.maximumWeight().isEmpty()) {
                throw new IllegalStateException(
                        "Cache region '" + cacheName + "': 'weigher-class' requires 'maximum-weight' to be set.");
            }

            caches.put(cacheName, new QuarkusPersistenceUnitCacheConfiguration.Cache(
                    memory.objectCount().orElse(QuarkusPersistenceUnitCacheConfiguration.Cache.DEFAULT.maxSize()),
                    cacheConfig.expiration().maxIdle()
                            .orElse(QuarkusPersistenceUnitCacheConfiguration.Cache.DEFAULT.maxIdle()),
                    memory.maximumWeight().orElse(-1L),
                    memory.weigherClass().orElse(null)));
        }
        return new QuarkusPersistenceUnitCacheConfiguration(caches);
    }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Remove one of the two properties: keep object-count for count-based eviction or maximum-weight for weight-based
  2. If switching to weight-based eviction, also configure weigher-class when objects vary in size
  3. Audit all cache regions in application.properties for this conflict

Example fix

// before
quarkus.hibernate-orm.cache."com.acme.Foo".memory.object-count=1000
quarkus.hibernate-orm.cache."com.acme.Foo".memory.maximum-weight=10MB
// after
quarkus.hibernate-orm.cache."com.acme.Foo".memory.maximum-weight=10MB
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast in tests if both eviction styles are set for a region
if (props.contains("quarkus.hibernate-orm.cache.X.memory.object-count")
 && props.contains("quarkus.hibernate-orm.cache.X.memory.maximum-weight"))
    throw new IllegalStateException("object-count and maximum-weight are mutually exclusive");

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/5703e7197820a875. Report an issue: GitHub.