我使用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);我想知道是否有一個解決方案,同時使用。
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
我使用了spring.jpa.properties.hibernate.globally_quoted_identifiers = true,因爲我希望Hibernate始終關閉,也在查詢中。我不想在查詢中手動執行此操作。 – drenda