I am using Hibernate and Spring for my web application.
In database operation, Hibernate is caching entities and returning them in next request without reading the actual database. I know this will reduce the load on database and improve performance.
But while this app still under construction, I need to load data from database in every request (testing reason).
Is there any way to force database read?
I became sure about the caching from this log4j message.
Returning cached instance of singleton bean 'HelloController'
DEBUG [http-bio-8080-exec-42] - Last-Modified value for [/myApp/../somePageId.html] is: -1
Do the read within a new transaction.
For example:
session.refresh(entity)
orentityManager.refresh(entity)
(if you use JPA) will give you fresh data from DB.Call refresh entity
session.refresh(entity)
or
Open new session then call
session2.get(EntityClass.class,id)
it will pull the entity from the database