You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.0如何避免实体或视图自动追加schema名称

解决Spring Boot 3.0实体自动追加schema名称的问题

以下几种方法可以解决实体表名被自动追加schema前缀的问题:

  • 全局配置Hibernate默认schema为空
    在application.properties或application.yml中添加如下配置:

    # application.properties
    spring.jpa.properties.hibernate.default_schema=
    

    或者YAML格式:

    # application.yml
    spring:
      jpa:
        properties:
          hibernate:
            default_schema: ''
    

    这个配置会让Hibernate不再自动为所有实体的表名追加schema前缀。

  • 单个实体显式指定空schema
    如果不需要全局修改,仅针对特定实体调整,可以在@Table注解里显式设置schema为空字符串:

    @Entity
    @Table(name = "employeee", schema = "")
    public class Employee {
        // 实体字段
    }
    
  • 检查数据源URL配置
    部分数据库驱动的URL中如果包含了指定schema的参数(比如MySQL的?currentSchema=mydb),也会导致自动追加schema前缀。需要检查并移除这类参数,确保数据源URL没有强制指定默认schema。

内容的提问来源于stack exchange,提问作者Praveen Kumar Dubey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 04:14:57