Issue
I have a Java application that loads data from a very large text file into MySQL via Hibernate. So far, the application seems to work OK - the data gets loaded.
Then I wanted to monitor the progress of the application while it was inserting data, so I wrote a small command-line utility that basically queries select count(*) from my_table;
.
The first time this query is run (from either the CLI or MySQL Workbench), I get the correct number of records, as expected. All subsequent executions of this query return the exact same number! Even though the data-loading application is still running!
If I stop and start the MySQL process, querying for the number of records shows the correct number, as the data-loading application would report it.
I've never seen anything like this before. It looks like there is some strange MySQL caching issue going on here, and I'm concerned it may cause problems for other non-Hibernate applications that may want to access this database.
Does anyone know how to tweak MySQL (or possibly Hibernate) so that MySQL always shows what's being added to the database?
Technical details:
- MySQL: 5.7.26, in a docker container, using InnoDB storage
- Hibernate version: 5.4.2.Final
- Spring version: 5.1.7.RELEASE
Solution
Calling FLUSH TABLES
seems to resolve this, in the sense that after I flush the tables, I can see how many records have been added by the application.
Answered By - FrustratedWithFormsDesigner
Answer Checked By - Marie Seifert (JavaFixing Admin)