Hibernate: Clean collection's 2nd level cache while cascade delete items

前端 未结 3 578
梦谈多话
梦谈多话 2021-02-08 19:04

I have a problem Hibernate does not update 2nd level cache for a collection of items which are subject of cascade removal.

Details

Assume we have an object Par

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-08 19:08

    The problem is that Hibernate doesn't actually do the delete. The database does that as part of a foreign key relationship, so Hibernate never sees all the objects that may get deleted and therefore, there is no way to update the cache that works in every case.

    I think your best bet is to flush the cache (or part of it) when you delete.

提交回复
热议问题