我目前正在使用Hibernate,Spring Boot和MariaDB实现应用程序。与数据库的连接如下:
application.yml ---------------------
spring:
jpa:
hibernate:
ddl-auto: create-drop
default_schema: mydb
datasource:
platform: mariadb
driver-class-name: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/mydb
username: mydb
password: mysecretpassword
initialization-mode: always
对象定义如下:
MyObject.java ----------------------
@Entity
@Table(name = "my_object", schema = "otherdb")
public class MyObject {
...
}
此外,我还定义了一个SQL文件,以确保两个使用的模式都存在:
schema.sql ---------------------------
CREATE SCHEMA IF NOT EXISTS mydb;
CREATE SCHEMA IF NOT EXISTS otherdb;
在内存中的HSQLDB上运行此命令非常正常,我收到如下消息:
...
2019-03-29 13:23:24.978 INFO 15876 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Hibernate: drop table otherdb.my_object if exists
...
但是当我在application.yml中切换到MariaDB时,出现了如下错误消息:
2019-03-29 14:27:09.166 INFO 2084 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Hibernate: drop table if exists my_object
2019-03-29 14:27:10.889 WARN 2084 --- [ main] o.h.t.s.i.ExceptionHandlerLoggedImpl : GenerationTarget encountered exception accepting command : Error executing DDL "drop table if exists my_object" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "drop table if exists my_object" via JDBC Statement
...
Caused by: java.sql.SQLException: (conn=250) No database selected
at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:258) ~[mariadb-java-client-2.3.0.jar:na]
...
Caused by: java.sql.SQLException: No database selected
Query is: drop table if exists my_object
java thread: main
...
请注意,模式名称在SQL命令中消失了。从我的角度来看,这会导致问题。
有没有办法解决此问题?
我前一阵子已经在休眠网站上报告了这个问题,但是看起来他们似乎太忙了,无法回答用户的问题/错误报告...:-(
https://discourse.hibernate.org/t/problem-in-mariadb-implementation/2531
感谢您的帮助!