java - hibernate + Spring 启动2 : Not checking the default schema

标签 java spring hibernate spring-boot

我正在使用 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/

相关文章:

java - 我怎样才能从不同的类(class)到达进度条?

java - 简单的退出按钮不起作用

java - 批量从线程返回值

java - Spring Batch - 为什么作业步骤 bean 是在 Web 上下文而不是作业上下文中创建/执行的?

java - Spring JSON 请求正文未映射到 Java POJO

java - hibernate : Java Application must be restarted for data to be realoaded

java - Hibernate - 继承中的外键和主键

java - 创建一个可供整个应用程序访问的类

java - 连接 "computer-database-jpa"Play 2.1 示例应用程序与 MySQL

java - 如何使用 @ID 和 @GenerateValue 从 Hibernate + JPA 中的序列获取 Oracle 生成值