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

时间:2018-09-03 10:41:10

标签: java mysql spring hibernate spring-boot

我有一个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最初能够生成架构,但是更新失败。

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

1 个答案:

答案 0 :(得分:0)

此问题不是由于减号引起的。

您应该尝试添加以下行之一的方言。SQ​​L方言使Hibernate为所选数据库生成更好的SQL

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

OR

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

OR

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

查看哪个适合您。