2017-06-05 25 views
2

我使用Hibernate + Spring JPA和Mysql 5.7作爲DBMS。我想用一些保留的關鍵字作爲列名和我eanbled:Hibernate 5.0.12使用Mysql 5.7錯誤地定義列定義

spring.jpa.properties.hibernate.globally_quoted_identifiers =真

某些列有一個自定義的定義,如:

@CreatedDate 
    @Column(updatable = false, columnDefinition = "DATETIME(6)") 
    private LocalDateTime createdDate; 

不幸的是Hibernate的翻譯本爲:

`created_date` `DATETIME(6)` 

,而不是

`created_date` DATETIME(6) 

我在Hibernate JIRA上打開了一個問題(JIRA);我想知道是否有一個解決方案,同時使用。

+0

1.括用方括號[]中的關鍵字。 @Column(name =「[DESC]」,nullable = false) public String getDesc(){ \t return this.desc; } 2.使用雙引號(「)將其括起來。 @Column(name =「\」DESC \「」,nullable = false) public String getDesc(){ \t return this.desc; } – Sudhakar

+0

我使用了spring.jpa.properties.hibernate.globally_quoted_identifiers = true,因爲我希望Hibernate始終關閉,也在查詢中。我不想在查詢中手動執行此操作。 – drenda

回答

0

我找到了正確的解決方案由於休眠人:

爲了避免列定義引述有特定的設置:

spring.jpa.properties.hibernate.globally_quoted_identifiers_skip_column_definitions=true 

不幸的是,現在,它的工作原理向後(see this bug):所以如果您想跳過列定義,則必須將其設置爲false

+0

不適用於我,使用spring啓動時從src/main/resources中的application.properties中設置屬性,但canot去掉引號。 –