mysql表名大写,造成jpa Table doesn't exist问题

报错信息

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:物理命名策略,用于转换“逻辑名称”(隐式或显式)的表或列成一个物理名称

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值