Native queries should not always clear the entire second-level cache

Description

Normally during a native query the entire second-level cache is cleared unless it is explicitly stated which entities the query affects. In our situation we want to execute the following PostgreSQL command which clearly doesn't affect any entity. If the second-level cache is always cleared this can potentially cause a major performance issue.

BulkOperationCleanupAction coordinates the cache cleanup. It uses the method affectedEntity() to check if a given entity is on the list of explicitly stated affected entities. If the list of affected entities is empty the entire cache is cleared, as can be seen here:

As a workaround I implemented following method which adds a dummy entry to the list of affected entities, effectively preventing the cache cleanup.

These issues are somewhat related:
https://hibernate.atlassian.net/browse/HHH-8487
https://hibernate.atlassian.net/browse/HHH-9315

Environment

None

Activity

Show:
Guillaume Smet
May 24, 2018, 12:51 PM

Looks legit to me. We should make a difference between:

  • we don't know which caches are affected;

  • we know none were affected.

Guillaume Smet
June 6, 2018, 12:23 PM

Moving to 6 as there's no chance we could implement that without changing the exposed API.

Assignee

Unassigned

Reporter

Petteri Pitkänen

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure