tl;dr - native queries bypass the persistence context and the cache.
This includes the queries you create by calling createNativeQuery
, obviously. But bulk updates (UPDATE
and DELETE
), though expressed in JPQL are translated to native queries by the provider and bypass the persistence context and the cache as well.
Thus flushing or executing other queries will not have the expected effect.
Besides, if your native queries have changed the data on entities that are managed in the current persistence context or are cached, the entities will not be refreshed automatically and will become stale.