[英]Hibernate + Spring boot 2: Not checking the default schema
我正在使用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
@ Abhi.G你已經在db中創建了schema / database嗎? 如果否,則手動創建,然后檢查它是否有效! 通常,如果您編寫了正確的屬性文件,那么它會創建數據庫本身。 請在您的文件中進行此更改,然后重試:spring.jpa.hibernate.ddl-auto = update
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.