Hi all
I am currently implementing an application using Hibernate, Spring Boot and MariaDB. The connection to the DB is as follows:
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
The objects are defined as follows:
MyObject.java ----------------------
@Entity
@Table(name = "my_object", schema = "otherdb")
public class MyObject {
...
}
Additionally, I have defined a SQL file where I make sure the two used schemas exists:
schema.sql ---------------------------
CREATE SCHEMA IF NOT EXISTS mydb;
CREATE SCHEMA IF NOT EXISTS otherdb;
Running this on the in-memory DB worked perfectly, I got messages like this:
...
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
...
But when I switched to MariaDB, I got error messages like this:
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
...
Please note, that the schema name disappeared in the SQL command. From my point of view, this causes the problem.
Please forgive me if this is a spring boot problem as it is my first approach to report this problem.
Thanks for helping!