MySql Migration issue


The issue is can be reproduced with MySQL database (I’ve tested PostgreSQL, H2 - looks like working fine). Sample jdbc url I am using: jdbc:mysql://localhost:32793/my-db with Hikari datasource. Preexisting table:

create table `my-db`.test (id_key VARCHAR(80) not null, primary key (id_key)) engine=InnoDB

And entity has 1 new column user_id:

@Table(name = "test")
public class Test {
  @Column(name = "id_key", columnDefinition = "VARCHAR(80)")
  private String idKey;
  @Column(name = "user_id")
  private String userId;

Generated migration SQL is:

alter table my-db.test add column user_id varchar(255)

Which ends with Exception:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '-db.test add column user_id varchar(255)' at line 1
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
	at java.lang.reflect.Constructor.newInstance(
	at com.mysql.jdbc.Util.handleNewInstance(
	at com.mysql.jdbc.Util.getInstance(
	at com.mysql.jdbc.SQLError.createSQLException(
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(
	at com.mysql.jdbc.MysqlIO.sendCommand(
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(
	at com.mysql.jdbc.ConnectionImpl.execSQL(
	at com.mysql.jdbc.ConnectionImpl.execSQL(
	at com.mysql.jdbc.StatementImpl.executeInternal(
	at com.mysql.jdbc.StatementImpl.execute(
	at com.zaxxer.hikari.pool.ProxyStatement.execute(
	at com.zaxxer.hikari.pool.HikariProxyStatement.execute(
	at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(
	... 60 common frames omitted

As MySQL requires identifier with dash to be quoted, e.g.:

alter table `my-db`.test add column user_id varchar(255)

I’ve tried to update hibernate, my-sql drivers to latest version - issue not solved.
I’ve tried to hibernate.globally_quoted_identifiers=true - table name is quted, but not catalog name. Issue not solved as well.


Maybe this issue is fixed by HHH-12939.

Try to replicate it with this test case template.


Hi @vlad. Thank you for quick reply. I’ve created test to highlight that catalog name is not quoted. I was running it over mysql_docker database profile.


How did you actually get the solution?


burger king survey kroger feedback


This only effect schema update (creation of tables works fine). I have run alter table sql queries manually and waiting for new release with fix