【发布时间】:2019-09-13 09:41:00
【问题描述】:
我正在使用 Hibernate 运行 Spring Boot 应用程序。我的“application.properties”中有以下属性来加载 Mysql 数据源并设置 Hibernate 属性。但是当我使用以下属性运行集成测试时,Hibernate 倾向于将“information_schema”检查为默认模式而不是“knowledgedb”模式,它会失败并出现以下异常。
Mysql 连接器版本:8.0.12
Spring Boot 版本:2.1.3.RELEASE
例外:
org.dbunit.dataset.DataSetException: java.sql.SQLSyntaxErrorException: Unknown table 'book_version' in information_schema
属性:
# Spring Datasource properties
spring.datasource.url=jdbc:mysql://localhost:3306/knowledgedb?createDatabaseIfNotExist=true&zeroDateTimeBehavior=CONVERT_TO_NULL&characterEncoding=utf8&characterSetResults=utf8&useTimezone=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false
spring.datasource.username=XX
spring.datasource.password=XX
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.hikari.maximum-pool-size=10
# Hibernate specific properties
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
spring.jpa.properties.hibernate.hbm2ddl.auto=validate
spring.jpa.properties.hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
spring.jpa.properties.hibernate.id.new_generator_mappings=false
spring.jpa.properties.hibernate.default_schema=knowledgedb
【问题讨论】:
-
尝试使用 databaseName=knowledgedb 而不是仅使用名称
-
@SyedMehtabHassan:SQL 不喜欢 URL 语法
-
你这是什么意思?
-
@SyedMehtabHassan:URL 中的 databaseName=knowledgedb 语法不正确
-
我没有使用过 SQL 但读过不止一个文档dzone.com/articles/…
标签: java spring hibernate spring-boot