Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force hibernate to load data from database?

Problem with hibernate:

I update a column "count" in a table "data" with a native query in my source code. Later I want to load all rows from table "data" but the value of column "count" has not changed.

Rows from table "data" are loaded with:

... .createQuery("from data") .setCacheable(false)
.list();

Any idea what's wrong ?

like image 289
Infos Avatar asked Oct 27 '25 08:10

Infos


1 Answers

setCacheable(false) isn't useful (it's the default). The cache it refers to is the second-level cache. You probably have loaded some entities in the session (i.e. the first-level cache) before executing your update query. In this case, the select query will perform against the database, but will return the already-loaded entities from the session. You thus need to evict these entities from the session before executing the select query, or to completely clear the session.

If the entities are cached in the second-level cache, then you also have to evict them from the second-level cache. See getCache.

like image 150
JB Nizet Avatar answered Oct 29 '25 06:10

JB Nizet