【问题标题】:Second level cache parent entity after native delete child with on delete set null原生删除子实体后的二级缓存父实体,删除集为空
【发布时间】:2020-09-20 07:01:28
【问题描述】:

我正在使用以下代码来驱逐被本机查询删除的缓存实体:

 entityManager.getEntityManagerFactory().getCache().evict( ChildEntity.class );

如果此实体类型是从其他实体 ParentEntity 引用的,那么在访问从以前缓存的 ParentEntity 引用的 ChildEntity 时的行为是什么?

ParentEntityon delete set null的外键拥有者,所以删除后子id在数据库中为null。

我认为缓存的 ParentEntity 已经知道旧的子 id,那么它会尝试通过 id 从数据库中获取子实体并失败吗?如果是这样,我是否也应该驱逐所有链接到 ChildEntity 的实体?

【问题讨论】:

    标签: hibernate jpa caching


    【解决方案1】:

    在使用 Hibernate 5.4.15 进行测试后,似乎在从二级缓存加载 Parent 实体时,它会尝试加载过时的子实体并抛出 EntityNotFoundException 将级联并最终返回 null(缺少)Parent 实体,但 Parent 实体仍存在于数据库中。

    打开了包含示例测试存储库的休眠错误HHH-14058

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-04
      • 2013-03-09
      • 2019-07-09
      相关资源
      最近更新 更多