更新时间:2023-02-05 13:54:02
在删除实体之前,我需要刷新该实体:
I needed to refresh the entity before removing it:
em.refresh(sampleContext);
em.remove(sampleContext);
以前,要删除的实体(sampleContext
)不知道sampleUser
与之关联(可能是因为sampleContext
是从缓存中获取的).在delete
之前执行refresh
可以确保从数据库中更新实体.
Earlier, the entity being deleted (sampleContext
) did not know that sampleUser
is associated with it (probably because sampleContext
was being fetched from cache). Doing a refresh
before delete
ensures that the entity is updated from the database.