I'm running a Java program with a connection to a mysql database using a jdbc url in hibernate.
The Java program performs selects on this database in order to insert the data obtained into another database.
The problem is that once the export is finished, I still get many queries of the form: /* mysql-connector-java-5.1.32 ( Revision: jess.balint@oracle.com-20140716155848-mlwabor66widht1n ) */SHOW VARIABLES WHERE Variable_name ='language (see complete abstract at the end)
These queries execute every 2 seconds.
And they generate new connections.
So after a while, the server is overloaded with open connections.
Apparently, it is not a problem with closing the connection for the export, as I use try-with-resources Statements that are supposed to automatically close the connections that have been opened.
Here is the abstract of the code for the connection:
public class MySessionProvider implements Provider<SessionFactory> {
@Config("qlik.export.db") private String database = "mydatabase";
@Config("qlik.export.url") private String url = "127.0.0.1:3306";
@Config("qlik.export.user") private String user = "myuser";
@Config("qlik.export.password") private String password = "mypassword";
@Override
public SessionFactory get() {
final Configuration cf = new Configuration();
cf.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
cf.setProperty("hibernate.connection.url", String.format("jdbc:mysql://%s/%s", url, database));
cf.setProperty("hibernate.connection.username", user);
cf.setProperty("hibernate.connection.password", password);
cf.setProperty("hibernate.hbm2ddl.auto", "update");
cf.setProperty("hibernate.dialect.storage_engine", "innodb");
cf.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL55Dialect");
cf.setProperty("hibernate.hikari.dataSource.useSSL", "false");
cf.setProperty("hbm2ddl.auto", "update");
cf.setProperty("javax.persistence.validation.mode", "none");
Here is the abstract of the logs for the useless selects :
2021-04-03T03:00:00.269907Z 183836 Connect qlik@192.168.1.11 on qlik using TCP/IP
2021-04-03T03:00:00.270146Z 183836 Query /* mysql-connector-java-5.1.32 ( Revision: jess.balint@oracle.com-20140716155848-mlwabor66widht1n ) */SHOW VARIABLES WHERE Variable_name ='language' OR Variable_name = 'net_write_timeout' OR Variable_name = 'interactive_timeout' OR Variable_name = 'wait_timeout' OR Variable_name = 'character_set_client' OR Variable_name = 'character_set_connection' OR Variable_name = 'character_set' OR Variable_name = 'character_set_server' OR Variable_name = 'tx_isolation' OR Variable_name = 'transaction_isolation' OR Variable_name = 'character_set_results' OR Variable_name = 'timezone' OR Variable_name = 'time_zone' OR Variable_name = 'system_time_zone' OR Variable_name = 'lower_case_table_names' OR Variable_name = 'max_allowed_packet' OR Variable_name = 'net_buffer_length' OR Variable_name = 'sql_mode' OR Variable_name = 'query_cache_type' OR Variable_name = 'query_cache_size' OR Variable_name = 'license' OR Variable_name = 'init_connect'
2021-04-03T03:00:00.272279Z 183836 Query /* mysql-connector-java-5.1.32 ( Revision: jess.balint@oracle.com-20140716155848-mlwabor66widht1n ) */SELECT @@session.auto_increment_increment
2021-04-03T03:00:00.272463Z 183836 Query SET NAMES utf8mb4
2021-04-03T03:00:00.272557Z 183836 Query SET character_set_results = NULL
2021-04-03T03:00:00.272641Z 183836 Query SET autocommit=1
2021-04-03T03:00:00.272736Z 183836 Query select @@session.tx_read_only
Here is the code for the export operation :
public void export() {
long entityCount = entityCount();
Log.info("Exporting %s entities of type: %s", entityCount, className().getSimpleName());
try (final Session qlikSession = sessionProvider.get().openSession()) {
for (int i = 0; i < entityCount; i += SCROLL_SIZE) {
List<Object> objects = getObjects(i);
process(qlikSession, objects);
}
} catch (HibernateException e) {
Log.error("Error while opening session: ", e);
}
}