【问题标题】:Hibernate + Spring boot 2: Not checking the default schemaHibernate + Spring boot 2:不检查默认模式
【发布时间】: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


【解决方案1】:

@Abhi.G 您是否已经在 db 中创建了模式/数据库?如果没有,则手动创建它,然后检查它是否有效!通常,如果您编写了正确的属性文件,那么它会自行创建数据库。 请在您的文件中进行此更改,然后重试: spring.jpa.hibernate.ddl-auto = 更新

【讨论】:

    猜你喜欢
    • 2019-05-22
    • 2016-08-01
    • 1970-01-01
    • 2015-08-31
    • 2014-12-23
    • 2018-09-21
    • 2019-08-16
    • 1970-01-01
    • 2019-06-23
    相关资源
    最近更新 更多