{"record":{"id":"37fb60525aafb66f","repo":"doctrine/orm","slug":"unrecognized-access-strategy-type-s","errorCode":null,"errorMessage":"Unrecognized access strategy type [%s]","messagePattern":"Unrecognized access strategy type \\[(.+?)\\]","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Cache/DefaultCacheFactory.php","lineNumber":88,"sourceCode":"        $usage  = $metadata->cache['usage'];\n\n        if ($usage === ClassMetadata::CACHE_USAGE_READ_ONLY) {\n            return new ReadOnlyCachedEntityPersister($persister, $region, $em, $metadata);\n        }\n\n        if ($usage === ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE) {\n            return new NonStrictReadWriteCachedEntityPersister($persister, $region, $em, $metadata);\n        }\n\n        if ($usage === ClassMetadata::CACHE_USAGE_READ_WRITE) {\n            if (! $region instanceof ConcurrentRegion) {\n                throw new InvalidArgumentException(sprintf('Unable to use access strategy type of [%s] without a ConcurrentRegion', $usage));\n            }\n\n            return new ReadWriteCachedEntityPersister($persister, $region, $em, $metadata);\n        }\n\n        throw new InvalidArgumentException(sprintf('Unrecognized access strategy type [%s]', $usage));\n    }\n\n    public function buildCachedCollectionPersister(\n        EntityManagerInterface $em,\n        CollectionPersister $persister,\n        AssociationMapping $mapping,\n    ): CachedCollectionPersister {\n        assert(isset($mapping->cache));\n        $usage  = $mapping->cache['usage'];\n        $region = $this->getRegion($mapping->cache);\n\n        if ($usage === ClassMetadata::CACHE_USAGE_READ_ONLY) {\n            return new ReadOnlyCachedCollectionPersister($persister, $region, $em, $mapping);\n        }\n\n        if ($usage === ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE) {\n            return new NonStrictReadWriteCachedCollectionPersister($persister, $region, $em, $mapping);\n        }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Cache/DefaultCacheFactory.php#L70-L106","documentation":"InvalidArgumentException from DefaultCacheFactory::buildCachedEntityPersister() (src/Cache/DefaultCacheFactory.php:88). The `usage` value in the entity's cache metadata is none of the recognized integers (ClassMetadata::CACHE_USAGE_READ_ONLY=1, CACHE_USAGE_NONSTRICT_READ_WRITE=2, CACHE_USAGE_READ_WRITE=3). The factory cannot pick a persister strategy for an unknown value.","triggerScenarios":"Programmatically built or serialized ClassMetadata whose cache['usage'] holds an invalid value: metadata produced by a custom mapping driver, metadata loaded from a stale metadata cache written by an older/other ORM version, or code assigning a string/int literal instead of the ClassMetadata constants.","commonSituations":"Deploying an ORM upgrade without clearing the metadata cache (old serialized ClassMetadata definitions); home-grown annotation/XML drivers that bypass the built-in constant resolution; importing mappings from another project with a custom usage enum.","solutions":["Clear the metadata cache (the query/metadata cache pool) so mappings are rebuilt with the installed ORM version.","In custom drivers/code, always set usage from ClassMetadata constants: $metadata->enableCache(usage: ClassMetadata::CACHE_USAGE_READ_ONLY).","Validate mapping files: usage must be READ_ONLY, NONSTRICT_READ_WRITE, or READ_WRITE (drivers convert these names to the constants).","Dump $metadata->cache for the offending class to find which value slips through and where it originates."],"exampleFix":"// before (custom driver writing a raw value)\n$metadata->cache = ['usage' => 0, 'region' => 'default']; // 0 is not a valid usage\n\n// after\nuse Doctrine\\ORM\\Mapping\\ClassMetadata;\n$metadata->enableCache(usage: ClassMetadata::CACHE_USAGE_READ_ONLY, region: 'default');","handlingStrategy":"validation","validationCode":"// When building metadata programmatically, validate the usage constant\n$usage = $metadata->cache['usage'] ?? null;\nassert(in_array($usage, [\n    ClassMetadata::CACHE_USAGE_READ_ONLY,\n    ClassMetadata::CACHE_USAGE_NONSTRICT_READ_WRITE,\n    ClassMetadata::CACHE_USAGE_READ_WRITE,\n], true));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use ClassMetadata::CACHE_USAGE_* constants instead of literal numbers.","Clear the metadata cache after every doctrine/orm upgrade.","Run doctrine:schema:validate (orm:validate) in CI to catch invalid cache metadata early."],"tags":["doctrine-orm","second-level-cache","metadata","mapping"],"backgroundTag":"invalid-cache-usage-strategy","analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}