Server does not read updated data from database

Description....

Our client updates the database. Then the Hibernate database is updated, the server should read the updated value from the database at this point. But this does not happen. To read the updated value from the database, I have to restart the server. Then I see the updated values.

What's happening?

+3
source share
3 answers

Hibernate uses an internal cache to optimize access to the database.

When you manually update the database, the Hibernate cache is not updated, so your values ​​are not displayed immediately. When you restart the server, the cache is freed, so your new values ​​appear.

Hibernate : http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-cache

+3

, , Hibernate ( JVM) , , , Hibernate API, Hibernate , .

, Hibernate, , . , evict() SessionFactory.

Hibernate:

19.3.

...

, SessionFactory , , .

sessionFactory.evict(Cat.class, catId); //evict a particular Cat
sessionFactory.evict(Cat.class);  //evict all Cats
sessionFactory.evictCollection("Cat.kittens", catId); //evict a particular collection of kittens
sessionFactory.evictCollection("Cat.kittens"); //evict all kitten collections

, , , , . - .

+1

?

, .

If you update the database using sleep mode, and if you cannot read the updated value, it may lead to a reset of the sleep mode configuration.

To immediately reset after a call HibernateDaoSupport.getHibernateTemplate().update(transientInstance);, you can callHibernateDaoSupport.getHibernateTemplate().flush();

0
source

Source: https://habr.com/ru/post/1762610/


All Articles