移除Entity属性后Doctrine ORM缓存错误求助
问题与修复方案请求
问题现象
将Entity实体的id属性移除,改为关联Base实体后,访问该Entity时出现两类缓存相关错误:
- 反射异常:提示对象不属于属性声明类
- PHP 8.2动态属性创建废弃警告
已尝试操作
- 执行
php config/cli-config.php orm:generate-proxies成功生成新代理类 - 尝试清理Doctrine缓存时,执行以下命令均报错Memcached连接失败:
orm:clear-cache:queryorm:clear-cache:metadataorm:clear-cache:result
临时解决方案
将ORM配置中的isDevMode设为true,暂时规避了错误,但需要找到正式修复方案。
运行环境
- PHP 8.2
- Doctrine ORM 3.1.0
- Doctrine DBAL 4.0.1
- Symfony cache 7.0.4
实体与数据库修改细节
原Entity实体代码
#[Id] #[Column(name: 'id', type: Types::INTEGER, updatable: false, options: ['unsigned' => true])] #[GeneratedValue] private int $id;
修改后Entity实体代码
#[Id] #[OneToOne(targetEntity: Base::class, inversedBy: 'entity')] #[JoinColumn(name: 'id', referencedColumnName: 'id', unique: true)] private Base $base;
对应数据库表结构
CREATE TABLE `entity` ( `id` int unsigned NOT NULL, PRIMARY KEY (`id`), KEY `entity_base_fk` (`id`), CONSTRAINT `entity_base_fk` FOREIGN KEY (`id`) REFERENCES `base` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
内容的提问来源于stack exchange,提问作者Unlucky
相关产品推荐
相关产品推荐

