[英]JPA generates incorrect SQL query for MySql8 with columdefinition
我正在使用 Springboot JPA 生成 MySql8 表。 它工作正常,除非我嘗試在 Column 注釋中使用 columndefinition。
@Column(columnDefinition = "boolean default false")
private Boolean example;
我嘗試用 TINYINT 替換 boolean,但據我所知,MySql8 應該支持 boolean。
我在表生成期間收到錯誤:
Caused by: java.sql.SQLSyntaxErrorException: 你的 SQL 語法有錯誤; 檢查與您的 MySQL 服務器版本對應的手冊,了解在第 5 行的 '
boolean default false
附近使用的正確語法
在我看來,生成的 SQL 語法有額外的引號,但我不確定如何解決該問題。
create table `exampleTable` (
`id` bigint not null auto_increment,
`example` `boolean default false`,
primary key (`id`)
)
編輯:我在這個問題中發現了我的問題: Spring JPA global_quoted_identifiers incorrectly quoting column type TEXT
如果你想將示例的默認值設置為 false 那么你可以這樣寫並從那里刪除 columnDefintion
私人 Boolean 示例=假;
通過將spring.jpa.properties.hibernate.globally_quoted_identifiers=false
添加到application.properties
文件來禁用引號
但禁用后,您將無法使用匹配 mysql 關鍵字的列名和表名(例如desc
)。 通過添加下划線解決方法:
@Column(name = "desc_")
String desc;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.