New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executeWithKey and MySQL throw SQLException #1670

Closed
noguespi opened this Issue Nov 25, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@noguespi

noguespi commented Nov 25, 2015

executeWithKey return the following exception :

Exception in thread "main" com.querydsl.core.QueryException: Caught SQLException for insert into `user` (`email`)
values (?)
    at com.querydsl.sql.DefaultSQLExceptionTranslator.translate(DefaultSQLExceptionTranslator.java:50)
    at com.querydsl.sql.Configuration.translate(Configuration.java:453)
    at com.querydsl.sql.dml.SQLInsertClause.executeWithKeys(SQLInsertClause.java:364)
    at com.querydsl.sql.dml.SQLInsertClause.executeWithKey(SQLInsertClause.java:172)
    at com.querydsl.sql.dml.SQLInsertClause.executeWithKey(SQLInsertClause.java:153)
    at com.serphacker.qdslbug.App.main(App.java:33)
Caused by: java.sql.SQLException: getGeneratedKeys error. Statement.RETURN_GENERATED_KEYS must be precised on connection.prepareStatement(String sql, int autoGeneratedKeys) or statement.executeUpdate(String sql, int autoGeneratedKeys)
    at org.mariadb.jdbc.MariaDbStatement.getGeneratedKeys(MariaDbStatement.java:800)
    at com.querydsl.sql.dml.SQLInsertClause.executeWithKeys(SQLInsertClause.java:351)
    ... 3 more

Tested with querydsl 4.0.6

        drop table if exists `user`;
        create table `user` (
            id int primary key auto_increment,
            email varchar(255)
        );
        Configuration conf = new Configuration(new MySQLTemplates());
        QUser t_user = QUser.user;

        Integer key = new SQLInsertClause(connection, conf, t_user)
            .set(t_user.email, "email")
            .executeWithKey(t_user.id);

Related to #1040

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 26, 2015

Member

Which version of the MariaDB driver do you use?

Member

timowest commented Nov 26, 2015

Which version of the MariaDB driver do you use?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 26, 2015

Member

Also do you use it with MySQL or MariaDB and which version?

Member

timowest commented Nov 26, 2015

Also do you use it with MySQL or MariaDB and which version?

@noguespi

This comment has been minimized.

Show comment
Hide comment
@noguespi

noguespi Nov 27, 2015

@timowest I tested against mariadb 10.0.22 but it looks like it's a mariadb driver issue :

mariadb-java-client 1.3.x : exception triggered
mariadb-java-client <= 1.2.x : ok, return generated keys
mysql-connector-java 5.1.37 : ok, return generated keys

noguespi commented Nov 27, 2015

@timowest I tested against mariadb 10.0.22 but it looks like it's a mariadb driver issue :

mariadb-java-client 1.3.x : exception triggered
mariadb-java-client <= 1.2.x : ok, return generated keys
mysql-connector-java 5.1.37 : ok, return generated keys

@noguespi noguespi closed this Nov 27, 2015

@noguespi noguespi reopened this Nov 27, 2015

@noguespi

This comment has been minimized.

Show comment
Hide comment
@noguespi

noguespi Nov 27, 2015

https://mariadb.com/kb/en/mariadb/mariadb-connector-j-130-release-notes/

maybe it is related to :

Notable changes and additions : Prepared statement on server side.

because the exception tell :

Caused by: java.sql.SQLException: getGeneratedKeys error. Statement.RETURN_GENERATED_KEYS must be precised on connection.prepareStatement(String sql, int autoGeneratedKeys) or statement.executeUpdate(String sql, int autoGeneratedKeys)

noguespi commented Nov 27, 2015

https://mariadb.com/kb/en/mariadb/mariadb-connector-j-130-release-notes/

maybe it is related to :

Notable changes and additions : Prepared statement on server side.

because the exception tell :

Caused by: java.sql.SQLException: getGeneratedKeys error. Statement.RETURN_GENERATED_KEYS must be precised on connection.prepareStatement(String sql, int autoGeneratedKeys) or statement.executeUpdate(String sql, int autoGeneratedKeys)
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 27, 2015

Member

Looks like a bug in the driver
https://github.com/MariaDB/mariadb-connector-j/blob/1.3.0/src/main/java/org/mariadb/jdbc/MariaDbConnection.java#L359

The flag Statement.RETURN_GENERATED_KEYS is missing.

Member

timowest commented Nov 27, 2015

Looks like a bug in the driver
https://github.com/MariaDB/mariadb-connector-j/blob/1.3.0/src/main/java/org/mariadb/jdbc/MariaDbConnection.java#L359

The flag Statement.RETURN_GENERATED_KEYS is missing.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 27, 2015

Member

@serphacker You should report that bug to MariaDB or switch to the MySQL driver.

Member

timowest commented Nov 27, 2015

@serphacker You should report that bug to MariaDB or switch to the MySQL driver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment