I have a java hibernate mysql project, one of the query keep failing to INSERT because I don't provide a value of the primary key AUTO_INCREMENT
.
I traced the Hibernate query, what Hibernate really send to MySql
SET GLOBAL general_log = 'ON';
SHOW GLOBAL VARIABLES LIKE 'general_log%';
and I tail the general_log file, there seems to be some session commands sent out such as SET sql_mode='STRICT_TRANS_TABLES', which some people consider we should not do. We should keep sql_mode as empty.
2019-03-22T15:16:11.207625Z 418 Query SET sql_mode='STRICT_TRANS_TABLES'
2019-03-22T15:16:11.207987Z 418 Query SHOW WARNINGS
2019-03-22T15:16:11.213624Z 418 Query SELECT @@session.transaction_isolation
2019-03-22T15:16:11.214109Z 418 Query SELECT @@session.transaction_read_only
2019-03-22T15:16:11.221148Z 418 Query SET autocommit=0
2019-03-22T15:16:11.252061Z 418 Query rollback
2019-03-22T15:16:11.252457Z 418 Query SET autocommit=1
2019-03-22T15:16:11.514489Z 418 Query SET autocommit=0
2019-03-22T15:16:11.545532Z 418 Query DELETE FROM `db1`.`table_a`
2019-03-22T15:16:11.549415Z 418 Query commit
2019-03-22T15:16:11.550861Z 418 Query SET autocommit=1
2019-03-22T15:16:11.551402Z 418 Query SET autocommit=0
2019-03-22T15:16:11.551896Z 418 Query ALTER TABLE `db1`.`table_a` AUTO_INCREMENT = 1
2019-03-22T15:16:11.567116Z 418 Query commit
2019-03-22T15:16:11.567413Z 418 Query SET autocommit=1
2019-03-22T15:16:11.568958Z 418 Query SET autocommit=0
2019-03-22T15:16:11.569947Z 418 Query INSERT INTO `db1`.`table_a` (key_reference, customer_obj_id, is_deleted) VALUES ('1ab0ccd3-3195-45eb-a65e-8ce8cf7b9808', 1, 0)
I have confirmed that in my my.cnf
[mysqld]
sql-mode=""
Using MySQL Workbench connecting to server:
SHOW VARIABLES LIKE 'sql_mode';
Variable_name sql_mode, Value=
So I have confirmed it's not from my server config. How do I stop hibernate from spewing SET sql_mode='STRICT_TRANS_TABLES'?