Can I add 'ON DELETE CASCADE' to tables managed by Hibernate?

后端 未结 6 1707
不知归路
不知归路 2021-01-04 00:14

I have some tables managed by Hibernate with various foreign key constraints. Cascade on delete is currently managed by Hibernate alone. For playing around with test data I

6条回答
  •  一整个雨季
    2021-01-04 00:56

    You mention for testing purposes. I'm guessing, execute some test, delete data, replay test...

    When using second-level caching or query cache, the cache will and up being stale if you directly remove the data from the database. This might result in unexpected test results.

    So yes, this will conflict with Hibernate if you use second-level / query caching as the entity's will not get evicted from cache. Make sure all caches get cleared after you directly deleted any data. See this question on how to clear cache.

    The official Hibernate docs also mention this:

    Be aware that caches are not aware of changes made to the persistent store by other applications. They can, however, be configured to regularly expire cached data.

提交回复
热议问题