Why does Hibernate session not reflect changes made outside the application
I am developing an application Java
that quickly checks for updates in a client database table and if any update is found then transfer it to the server database using Hibernate
and MySQL
.
- This works well, when we change the database using hibernate BUT session , when I change the value of the database table using
MySQL Workbench
then it will return records which are as before.
How can hibernate session refresh on external table changes.
public List<com.ctpl.models.client.MasterTable> getAllClientMasterTableWithServerFlag() {
try {
clientSession = ClientHibernateUtil.getSessionFactory().openSession();
clientSession.flush();
Criteria criteria = clientSession.createCriteria(com.ctpl.models.client.MasterTable.class);
criteria.add(Restrictions.eq("serverFlag", 0));
List<com.ctpl.models.client.MasterTable> clientMasterTables = criteria.list();
clientSession.close();
return clientMasterTables;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
What am I missing here?
+3
source to share
2 answers
We just need to add the connection pool to hibernate like below ...
Found the best way to easily implement it using this example
+1
source to share
Have a look at Session.clear () or evict method
Refer to this article:
http://howtodoinjava.com/2013/07/01/understanding-hibernate-first-level-cache-with-example/
Hope it helps
+2
source to share