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.
Looks legit to me. We should make a difference between:
we don't know which caches are affected;
we know none were affected.
Moving to 6 as there's no chance we could implement that without changing the exposed API.