Is there any way to bypass the first level cache for an entity or query?

I have an entity for a table that is updated constantly. Although the first level cache is fine for most entities, it actually just gets in the way for this specific entity. Right now it seems like the only way for me to force a manual refresh when I do a JPQL query for this entity is either to:

a. close and reacquire the entity manager, or
b. iterate all entities returned by my query and refresh them individually.

These are easy to do code-wise but I don’t feel very satisfied in terms of performance.
I am also doing this for the query:
.setHint(“javax.persistence.cache.retrieveMode”, CacheRetrieveMode.BYPASS)

…but it has no effect. I’m guessing this is only relevant for the second-level cache? Is there any way to do what I need to do without having to resort to either of the two approaches I described?

Even if you could do that, it would still not guarantee you will see the latest entity version.

What if right after the query is executed, the entity is changed anew? So, you will always see a snapshot.

Use a DTO projection if you want to bypass the cache or fetch the entity in read-only mode.

Hmm I didn’t see mention of caching in that article, is this the intended one?

Hmm I didn’t see mention of caching in that article, is this the intended one?

If you click on the link I gave you, then you will. That’s not the link I provided you, that’s a different article you found yourself.