解決(springboot項目)mysql表名大寫,造成jpa Table doesn't exist問題


這個問題有2種解決方法:

我的報錯是:

 java.sql.SQLSyntaxErrorException: Table 'gaei_ms.gaei_work_task' doesn't exist

 

方法一:

轉自:https://confluence.atlassian.com/fishkb/table-xxx-doesn-t-exist-error-with-mysql-server-302810019.html

  1. 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")
  2. net.java.ao.sql.ActiveObjectSqlException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'fecru.AO_B434B9_WEB_HOOK' doesn't exist
  3. at com.atlassian.activeobjects.internal.EntityManagedActiveObjects.find(EntityManagedActiveObjects.java:114)
  4. at com.atlassian.activeobjects.osgi.DelegatingActiveObjects.find(DelegatingActiveObjects.java:71)
  5. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  6. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  7. ...
  8. Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'fecru.AO_B434B9_WEB_HOOK' doesn't exist

原因:

MySQL對lower_case_table_names使用區分大小寫的表名比較設置  (可能值為'0')。但是,FishEye在表名  FE-4276中不一致-數據庫表OPEN的大小寫不一致您可以使用以下查詢確認設置: 

show variables like 'lower_case_table_names'; 

解決:

  1.  在MySQL中設置  lower_case_table_names的值為'0'
  2. 重新啟動MySQL和FishEye / Crucible。

 

 

 

方法二:

我的情況是springboot項目,配置文件的改法略有不同:

我的改法是在配置文件中加上這一行:

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

 

以下轉自:https://blog.csdn.net/Halleycomett/article/details/78638639

報錯信息

  1. org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
  2.  
  3.  
  4. Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table XXX doesn't exist

報錯原因調查

mysql里實際表名都是大寫

嘗試在entity上標記表名大寫,實際測試無效,仍然找不到表

  1. @Entity
  2. @Data
  3. @Table(name = "T_BASE_ORDER_PRINT_CLIENT")
  4. public class MerchantPrinter {
  5.  
  6. @Id
  7. @Column(name = "print_client_id")
  8. private String id;
  9.  
  10. @Column(name = "merchant_id")
  11. private String merchantId;
  12.  
  13. private String imei;
  14.  
  15. }

最終的解決方案

  1. 在spring jpa配置中增加physical-strategy配置解決問題
  2.  
  3. spring:
  4. datasource:
  5. driver- class-name: com.mysql.jdbc.Driver
  6. url: jdbc:mysql: //XXX:3306/dbname
  7. username: root
  8. password: *******
  9. schema:
  10. jpa:
  11. hibernate:
  12. ddl-auto: none
  13. naming:
  14. physical-strategy: org .hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
  15. show-sql: true

physical naming strategy :used to convert a “logical name” (either implicit or explicit) name of a table or column into a physical name (e.g. following corporate naming guidelines) 
physical naming strategy:物理命名策略,用於轉換“邏輯名稱”(隱式或顯式)的表或列成一個物理名稱


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM