报错信息
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
报错原因调查
mysql里实际表名都是大写
尝试在entity上标记表名大写,实际测试无效,仍然找不到表
@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.Driver
url: jdbc:mysql://XXX:3306/dbname
username: root
password: *******
schema:
jpa:
hibernate:
ddl-auto: none
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
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:物理命名策略,用于转换“逻辑名称”(隐式或显式)的表或列成一个物理名称