Reputation: 2151
I am developing a Java
Application which rapidly checks for updates in client database table and if any update is found then transfer it to the server database using Hibernate
and MySQL
.
MySQL Workbench
then it will return the records which are as before.How can I get updated with hibernate session on outside changes in table.
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 ?
Upvotes: 3
Views: 1550
Reputation: 2151
We just need to add connection pooling in hibernate like following...
Found best way to implement it easily using this example
Upvotes: 1
Reputation: 522
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 that helps
Upvotes: 2