我正在使用 Hibernate 运行 Spring Boot 应用程序。我的“application.properties”中有以下属性来加载 Mysql 数据源并设置 Hibernate 属性。但是当我使用以下属性运行集成测试时,Hibernate 倾向于检查“information_schema”作为默认架构而不是“knowledgedb”架构,并且它会失败并出现以下异常。
Mysql连接器版本:8.0.12
Spring Boot版本:2.1.3.RELEASE
异常(exception):
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
最佳答案
@Abhi.G 您是否已经在数据库中创建了架构/数据库??如果没有,则手动创建它,然后检查它是否有效!通常,如果您编写了正确的属性文件,那么它会自行创建数据库。 请在您的文件中进行此更改,然后重试: spring.jpa.hibernate.ddl-auto = 更新
关于java - hibernate + Spring 启动2 : Not checking the default schema,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55824167/