{"record":{"id":"599d92bd0aefc663","repo":"hibernate/hibernate-orm","slug":"inconsistent-configuration-hibernate-query-plan-599d92","errorCode":null,"errorMessage":"Inconsistent configuration: 'hibernate.query.plan_cache_max_size' can't be set to a negative value (to disable the query plan cache set 'hibernate.query.plan_cache_enabled' to 'false')","messagePattern":"Inconsistent configuration: 'hibernate\\.query\\.plan_cache_max_size' can't be set to a negative value \\(to disable the query plan cache set 'hibernate\\.query\\.plan_cache_enabled' to 'false'\\)","errorType":"exception","errorClass":"ConfigurationException","httpStatus":null,"severity":"critical","filePath":"hibernate-core/src/main/java/org/hibernate/query/internal/QueryEngineImpl.java","lineNumber":200,"sourceCode":"\n\t\tfinal Integer explicitMaxPlanSize = getInteger(\n\t\t\t\tQUERY_PLAN_CACHE_MAX_SIZE,\n\t\t\t\tproperties\n\t\t);\n\n\t\t//Let's avoid some confusion and check settings consistency:\n\t\tfinal int appliedMaxPlanSize =\n\t\t\t\texplicitMaxPlanSize == null\n\t\t\t\t\t\t? DEFAULT_QUERY_PLAN_MAX_COUNT\n\t\t\t\t\t\t: explicitMaxPlanSize;\n\t\tif ( !useCache && explicitMaxPlanSize != null && appliedMaxPlanSize > 0 ) {\n\t\t\tthrow new ConfigurationException( \"Inconsistent configuration: '\" + QUERY_PLAN_CACHE_MAX_SIZE\n\t\t\t\t\t\t\t\t\t\t\t\t+ \"' can only be set to a value greater than zero when '\"\n\t\t\t\t\t\t\t\t\t\t\t\t+ QUERY_PLAN_CACHE_ENABLED + \"' is enabled\" );\n\t\t}\n\n\t\tif ( appliedMaxPlanSize < 0 ) {\n\t\t\tthrow new ConfigurationException( \"Inconsistent configuration: '\" + QUERY_PLAN_CACHE_MAX_SIZE\n\t\t\t\t\t\t\t\t\t\t\t\t+ \"' can't be set to a negative value (to disable the query plan cache set '\"\n\t\t\t\t\t\t\t\t\t\t\t\t+ QUERY_PLAN_CACHE_ENABLED + \"' to 'false')\" );\n\t\t}\n\n\t\treturn useCache\n\t\t\t\t? new QueryInterpretationCacheStandardImpl( appliedMaxPlanSize, serviceRegistry )\n\t\t\t\t: new QueryInterpretationCacheDisabledImpl( serviceRegistry ); // disabled\n\t}\n\n\t@Override\n\tpublic void validateNamedQueries() {\n\t\tnamedObjectRepository.validateNamedQueries( this );\n\t}\n\n\t@Override\n\tpublic NamedObjectRepository getNamedObjectRepository() {\n\t\treturn namedObjectRepository;\n\t}","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/internal/QueryEngineImpl.java#L182-L218","documentation":"The same bootstrap-time validation in QueryEngineImpl rejects a negative hibernate.query.plan_cache_max_size with ConfigurationException. The message tells you the supported way to disable the cache: set hibernate.query.plan_cache_enabled=false rather than abusing a negative size. Startup aborts while the SessionFactory is being created.","triggerScenarios":"Any configuration source containing hibernate.query.plan_cache_max_size=-1 (or any negative value), commonly an attempt to disable the plan cache by size instead of using the enabled flag.","commonSituations":"Copying an old snippet that used a negative size as a disable switch; environment-variable arithmetic producing a negative number; merged configs where a default of -1 meets an unset enabled flag.","solutions":["Set hibernate.query.plan_cache_max_size to a positive number, or remove the key entirely.","To turn the cache off, use hibernate.query.plan_cache_enabled=false.","Validate numeric config values at deployment time if they come from environment variables."],"exampleFix":"# before\nhibernate.query.plan_cache_max_size=-1\n\n# after\nhibernate.query.plan_cache_enabled=false","handlingStrategy":"validation","validationCode":"static void checkPlanCacheMaxSize(java.util.Map<String, Object> cfg) {\n    Object size = cfg.get(\"hibernate.query.plan_cache_max_size\");\n    if (size != null && ((Number) size).intValue() < 0)\n        throw new IllegalArgumentException(\n            \"plan_cache_max_size must be >= 0; disable the cache with plan_cache_enabled=false\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    emf = Persistence.createEntityManagerFactory(\"pu\");\n} catch (Exception e) {\n    // look for ConfigurationException about plan_cache_max_size and fix the property\n}","preventionTips":["Never use a negative size to disable the plan cache; use the enabled flag.","Validate numeric Hibernate settings sourced from environment variables at deploy time.","Boot the persistence unit in a CI smoke test."],"tags":["hibernate","configuration","query-plan-cache","startup-failure","invalid-value"],"backgroundTag":"invalid-configuration-value","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}