简体   繁体   English

Hibernate + Spring启动2:不检查默认架构

[英]Hibernate + Spring boot 2: Not checking the default schema

I am running a Spring Boot app with Hibernate. 我正在使用Hibernate运行Spring Boot应用程序。 I have the following properties in my "application.properties" to load a Mysql Datasource and set Hibernate properties. 我在“application.properties”中有以下属性来加载Mysql数据源并设置Hibernate属性。 But When I run Integration tests with the following properties, Hibernate tends to check "information_schema" as default schema and not "knowledgedb" schema and it fails with the below exception. 但是当我使用以下属性运行集成测试时,Hibernate倾向于将“information_schema”检查为默认模式而不是“knowledgedb”模式,并且它失败并出现以下异常。

Mysql connector version: 8.0.12 Mysql连接器版本:8.0.12

Spring Boot version: 2.1.3.RELEASE Spring Boot版本:2.1.3.RELEASE

Exception: 例外:

org.dbunit.dataset.DataSetException: java.sql.SQLSyntaxErrorException: Unknown table 'book_version' in information_schema

properties: 特性:

# 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 have you already created schema/database into db ?? @ Abhi.G你已经在db中创建了schema / database吗? If no then create it manually and then check whether it works or not ! 如果否,则手动创建,然后检查它是否有效! Normally,if you have written correct property file then it creates database itself. 通常,如果您编写了正确的属性文件,那么它会创建数据库本身。 Please do this change in your file and try again : spring.jpa.hibernate.ddl-auto = update 请在您的文件中进行此更改,然后重试:spring.jpa.hibernate.ddl-auto = update

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM