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

前端 未结 3 546
梦谈多话
梦谈多话 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:30

    I've been struggling with other problem requiring remove collection from cache and I've worked out some solution. I don't know if it is possible to update the collection's cache automatically on cascade delete, but if you've tried SessionFactory.evictCollection() and it worked, I think that this solution can be transactional safe and it works also:

    if (MYCOLLECTION instanceof AbstractPersistentCollection) ((AbstractPersistentCollection) MYCOLLECTION).dirty();

提交回复
热议问题