• JPA 表名大小写问题


    JPA 默认会将实体中的 TABLE_NAME 转成小写如

    @Entity
    @Table(name = "EMPLOYEE")
    public class Employee {
    
        @Id
        private String id;

    会报:java.sql.SQLSyntaxErrorException: Table 'mysql.employee' doesn't exist 表名已经被转成了小写

    可以添加一个策略解决此问题

    package com.iron.config;
    
    import org.hibernate.boot.model.naming.Identifier;
    import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
    import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
    
    /**
     * Created by Jimmy on 2020/3/13.
     */
    public class UpperTableStrategy extends PhysicalNamingStrategyStandardImpl {
    
        private static final long serialVersionUID = 1383021413247872469L;
    
    
        @Override
        public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
            // 将表名全部转换成大写
            String tableName = name.getText().toUpperCase();
    
            return name.toIdentifier(tableName);
        }
    }

    application.yml 配置文件中添加相应的配置,启用上面的策略

    server:
      port: 8081
    spring:
      jpa:
        show-sql: true
        hibernate:
          naming:
            physical-strategy: com.iron.config.UpperTableStrategy
      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://172.17.127.53:3306/mysql?Unicode=true&characterEncoding=UTF-8
        username: root
        password: 123
  • 相关阅读:
    对websoceket进行压力测试(一)
    学习springboot的一个网站
    重装mysql数据库
    websocket扫盲:基础知识(二)
    json-lib 之jsonConfig详细使用
    hibernate的like用法(用占位符解决)
    【转载】hibernate查询参数绑定
    Struts2 Anotation action
    PLSQL怎样导出oracle表结构
    从命令行启动oracle服务
  • 原文地址:https://www.cnblogs.com/vipsoft/p/12490033.html
Copyright © 2020-2023  润新知