[CONJ-760] Cannot insert into a table named "position" Created: 2020-02-12  Updated: 2022-08-16  Resolved: 2022-08-16

Status: Closed
Project: MariaDB Connector/J
Component/s: MySQL compatibility
Affects Version/s: 2.5.4
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Sebastian Brandt Assignee: Diego Dupin
Resolution: Cannot Reproduce Votes: 0
Labels: None
Environment:

Linux, Java 11, Spring/JPA/Hibernate



 Description   

We are using a MySQL 5.6 compatible DB (AWS Aurora Serverless 5.6.10a) and have a table named "position".
Until now, we used the MySQL connector and had no issues accessing that table.
Recently we tried to switch to MariaDB Connector/J 2.5.4 and encountered a surprising issue:

While selecting from or updating that table works fine using MariaDB Connector/J, inserting into the "position" table raises the error:

java.sql.SQLSyntaxErrorException: (conn=106) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'position (asset_name, [...]

The issue is that the table is named "position", though "position" does not seem to be a reserved keyword in either MariaDB or MySQL (according to online docs). Also it's weird that selecting and updating works but not inserting...

We could of course work around this by putting position in ticks (`position`) or by renaming the table but it struck us as weird and maybe it's a bug in MariaDB Connector/J.



 Comments   
Comment by Diego Dupin [ 2020-02-17 ]

position is a reserved word, and is now added to https://mariadb.com/kb/en/reserved-words/ .
So MariaDB connector correctly send an error message.

Problem is that i don't see why this would have work with MySQL connector. C/J does some parsing of query, but i've never seen any quote added automagically. I've tryed to make it work with MySQL connector without success.

Could you indicate the connection string you use with MySQL, ? Me might have to change something in order to be compatible.

Comment by Sebastian Brandt [ 2020-02-18 ]

I replayed the operations on a local test MySQL 5.6 instance to highlight the issue:

MySQL connector connection string is: jdbc:mysql://localhost:3306/TEST?characterEncoding=UTF-8
MariaDB connector connection string is: jdbc:mariadb://localhost:3306/TEST?characterEncoding=UTF-8

The table was created using the MySQL Connector:
TEST> CREATE TABLE position (
id bigint(20) NOT NULL AUTO_INCREMENT,
asset_name varchar(190) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB
[2020-02-18 09:14:59] completed in 74 ms

DMLs using MySQL Connector:
-------------------------------------------------
TEST> INSERT INTO position (asset_name) values ('TESTVAL')
[2020-02-18 09:15:27] 1 row affected in 13 ms

TEST> COMMIT
[2020-02-18 09:15:28] completed in 2 ms

TEST> SELECT * FROM position
[2020-02-18 09:15:29] 1 row retrieved starting from 1 in 37 ms (execution: 7 ms, fetching: 30 ms)

TEST> UPDATE position SET asset_name = 'NEWTESTVAL' where id = 1
[2020-02-18 09:15:31] 1 row affected in 21 ms

TEST> COMMIT
[2020-02-18 09:15:32] completed in 1 ms

DMLs using MariaDB Connector
(there's already one row in the table from above INSERT using MySQL connector) :
----------------------------------------------------
TEST> SELECT * FROM position
[2020-02-18 09:15:38] 1 row retrieved starting from 1 in 34 ms (execution: 5 ms, fetching: 29 ms)

TEST> UPDATE position SET asset_name = 'NEWTESTVAL2' where id = 1
[2020-02-18 09:15:41] 1 row affected in 15 ms

TEST> COMMIT
[2020-02-18 09:15:44] completed in 1 ms

TEST> SELECT * FROM position
[2020-02-18 09:15:46] 1 row retrieved starting from 1 in 33 ms (execution: 9 ms, fetching: 24 ms)

TEST> INSERT INTO position (asset_name) values ('TESTVAL2')
[2020-02-18 09:18:48] [42000][1064] (conn=22) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'position (asset_name) values ('TESTVAL2')' at line 1
[2020-02-18 09:18:48] [42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'position (asset_name) values ('TESTVAL2')' at line 1
[2020-02-18 09:18:48] Query is: INSERT INTO position (asset_name) values ('TESTVAL2')
[2020-02-18 09:18:48] java thread: RMI TCP Connection(13)-127.0.0.1

Comment by Diego Dupin [ 2020-03-04 ]

ahh, i missed the hibernate part. hibernate construct the query according to dialect configuration.
There is probably something not well detected / configured.

Either the dialect configured (org.hibernate.dialect.MySQL55Dialect ?) is incorrect or more probably hibernate automatic resolver has an issue .

Could you indicate how this part is configured, and hibernate version you use ?

I've just check latest version of resolver, but this seems ok (https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/dialect/Database.java#L275)

Comment by Sebastian Brandt [ 2020-03-30 ]

In my comment from 2020-02-17 9:20 I was able to reproduce the issue without Hibernate, with just plan JDBC. Therefore I have some doubts it is related to Hibenate...

Comment by Diego Dupin [ 2022-08-16 ]

closing since never reproduced

Generated at Thu Feb 08 03:18:07 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.