Hibernate 5.0.12 错误的列定义转义与 Mysql 5.7

dre*_*nda 4 mysql spring hibernate jpa

我使用 Hibernate + Spring JPA 和 Mysql 5.7 作为 DBMS。我想使用一些保留关键字作为列名,为此我启用了:

spring.jpa.properties.hibernate.globally_quoted_identifiers=true

某些列具有自定义定义,例如:

@CreatedDate
    @Column(updatable = false, columnDefinition = "DATETIME(6)")
    private LocalDateTime createdDate;
Run Code Online (Sandbox Code Playgroud)

不幸的是,Hibernate 将此翻译为:

`created_date` `DATETIME(6)`
Run Code Online (Sandbox Code Playgroud)

代替

`created_date` DATETIME(6)
Run Code Online (Sandbox Code Playgroud)

我在 Hibernate JIRA (JIRA)上打开了一个问题;我想知道是否有同时使用的解决方法。

dre*_*nda 5

感谢 Hibernate 人员,我找到了正确的解决方案:

为了避免引用列定义,有一个特定的设置:

spring.jpa.properties.hibernate.globally_quoted_identifiers_skip_column_definitions=true
Run Code Online (Sandbox Code Playgroud)

不幸的是,现在,它向后工作(请参阅此错误):因此,如果您想跳过列定义,则必须将其设置为false