zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    win10 uwp iot
    app已损坏,打不开。你应该将它移到废纸篓
    DIVCNT2&&3
    win10 uwp iot
    win10 uwp 屏幕常亮
    win10 uwp 屏幕常亮
    win10 uwp 使用油墨输入
    win10 uwp 使用油墨输入
    win10 UWP 全屏
    win10 UWP 全屏
  • 原文地址:https://www.cnblogs.com/vipsoft/p/12490033.html
Copyright © 2011-2022 走看看