繁体   English   中英

Spring Hibernate模式更新不适用于负号数据库名称

[英]Spring Hibernate schema update not works with minus sign in database name

我有一个Spring Boot应用程序

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
...
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

并将休眠设置为访问application.properties中的数据库

spring.datasource.url=jdbc:mysql://localhost:3306/banquets-booking?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=1
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# this not helps as puts in quotes table field name only
#spring.jpa.properties.hibernate.globally_quoted_identifiers=true

#update validate create create-delete
spring.jpa.hibernate.ddl-auto=update

现在,我向实体添加了一个新字段,但是更新失败:

2018-09-03 13:05:34.893 TRACE 20867 --- [  restartedMain] org.hibernate.type.TypeFactory           : Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@56922754
Hibernate: 

    alter table banquets-booking.sub_event 
       add column outlet_id bigint
2018-09-03 13:05:35.841  WARN 20867 --- [  restartedMain] o.h.t.s.i.ExceptionHandlerLoggedImpl     : GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement

这看起来像个错误,因为Hibernate最初能够生成架构,但是在更新时失败。

如何在不重命名数据库的情况下解决此问题?

此问题不是因为减号。

您应该尝试添加以下方言之一这样的方言.SQL方言使Hibernate为所选数据库生成更好的SQL

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

要么

spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.MySQLMyISAMDialect 

要么

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLInnoDBDialect 

看看哪个适合您。

暂无
暂无

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

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