Answer the question
In order to leave comments, you need to log in
How can I get "fresh" data from hibernate?
The problem is this: I have a MySQL DB. First, the first Java application will start, it will hibernate on DB1. Then another application updates the records in the same database1. After that, when trying to get the updated data in the first application through a SQL query, hibernate still returns the old data, as if from a cache. Google did not help: I tried to disable the level 2 cache, session.clear(), etc. What could be the problem?
Query query = session.createSQLQuery("select id from users where city = 'Moscow' limit 1");
List result = query.list();
Answer the question
In order to leave comments, you need to log in
Did you do session.flush() or transaction.commit() (depending on how you implement requests) after you sent new data?
The save and saveOrUpdate methods send information to the cache, after which the request must be confirmed in order for it to be executed.
This is how it should be when changing data:
Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question