Hibernate does not support database name containing a dash (e.g. my-db) sign when using MySQL

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(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
	at com.mysql.jdbc.Util.getInstance(Util.java:408)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:943)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2483)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2441)
	at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:845)
	at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:745)
	at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95)
	at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java)
	at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
	... 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.

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 https://github.com/hibernate/hibernate-orm/pull/2528.

Upgrading to 5.4.0.CR1 solved the problem. Thank you.

As for the connection to MySQL database, I found Delphi and MySQL Connector and solved such a problem.