I am using Hibernate with MySql, when i start my local server and pass queries the values returned are consistent and correct. If i update the database either via a updateQuery or manually by opening MySql workbench, the select query sometime returns the old value and sometimes the new value. Is this a known issue? I’ve made sure that I have a beginTransaction and commitTransaction before every select call and also before any insert/update transaction. The funny thing is until i touch the database after a restart the values returned are perfect.
Share
Please try the same thing again with disabled Hibernate caching (second-level cache and query cache). To do this, set the following properties to false, either in your Hibernate or Spring configuration:
This should cause Hibernate to go back to the database each time and it should show the results as they are in the database. Please note that Hibernate still uses the first-level session cache, which is used during the lifetime of a session (typically one transaction). Other than that, it should now always go to the database and should show up-to-date results even if you change the data directly in the DB.
Once you have made sure that this works, you can enable the caches again and check that they’re working as designed. Please make sure to cross-read the Hibernate documentation on caching, especially the various caching strategies (read-only, read-write, …): http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/performance.html#performance-cache