解决(springboot项目)mysql表名大写,造成jpa Table doesn't exist问题
生活随笔
收集整理的這篇文章主要介紹了
解决(springboot项目)mysql表名大写,造成jpa Table doesn't exist问题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
這個(gè)問題有2種解決方法:
我的報(bào)錯(cuò)是:
java.sql.SQLSyntaxErrorException: Table 'gaei_ms.gaei_work_task' doesn't exist方法一:
轉(zhuǎn)自:https://confluence.atlassian.com/fishkb/table-xxx-doesn-t-exist-error-with-mysql-server-302810019.html
2012-09-05 10:12:30,728 ERROR [btpool0-472 ] fisheye.app TotalityFilter-logExceptionDetails - Exception "com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'fecru.AO_B434B9_WEB_HOOK' doesn't exist" (net.java.ao.sql.ActiveObjectSqlException) while processing "/plugins/servlet/webhooks/list" (Referer:"https://fisheye.bln.native-instruments.de/admin/viewServerSettings.do") net.java.ao.sql.ActiveObjectSqlException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'fecru.AO_B434B9_WEB_HOOK' doesn't existat com.atlassian.activeobjects.internal.EntityManagedActiveObjects.find(EntityManagedActiveObjects.java:114)at com.atlassian.activeobjects.osgi.DelegatingActiveObjects.find(DelegatingActiveObjects.java:71)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ... Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'fecru.AO_B434B9_WEB_HOOK' doesn't exist原因:
MySQL對(duì)lower_case_table_names使用區(qū)分大小寫的表名比較設(shè)置??(可能值為'0')。但是,FishEye在表名??FE-4276中不一致-數(shù)據(jù)庫表OPEN的大小寫不一致。您可以使用以下查詢確認(rèn)設(shè)置:?
show variables like 'lower_case_table_names';解決:
方法二:
我的情況是springboot項(xiàng)目,配置文件的改法略有不同:我的改法是在配置文件中加上這一行:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl以下轉(zhuǎn)自:https://blog.csdn.net/Halleycomett/article/details/78638639
報(bào)錯(cuò)信息
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table XXX doesn't exist報(bào)錯(cuò)原因調(diào)查
mysql里實(shí)際表名都是大寫
嘗試在entity上標(biāo)記表名大寫,實(shí)際測(cè)試無效,仍然找不到表
@Entity @Data @Table(name = "T_BASE_ORDER_PRINT_CLIENT") public class MerchantPrinter {@Id@Column(name = "print_client_id")private String id;@Column(name = "merchant_id")private String merchantId;private String imei;}最終的解決方案
在spring jpa配置中增加physical-strategy配置解決問題spring:datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://XXX:3306/dbnameusername: rootpassword: *******schema:jpa:hibernate:ddl-auto: nonenaming:physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImplshow-sql: truephysical naming strategy :used to convert a “l(fā)ogical name” (either implicit or explicit) name of a table or column into a physical name (e.g. following corporate naming guidelines)?
physical naming strategy:物理命名策略,用于轉(zhuǎn)換“邏輯名稱”(隱式或顯式)的表或列成一個(gè)物理名稱
總結(jié)
以上是生活随笔為你收集整理的解决(springboot项目)mysql表名大写,造成jpa Table doesn't exist问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 解决:Failed to execute
- 下一篇: 分享21款漂亮的WordPress高级主