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

Spring Boot 3.0.5中spring.jpa.hibernate.ddl-auto配置失效问题咨询

Spring Boot 3.0.5中Hibernate ddl-auto配置不生效的问题
  • 问题现象:
    在Spring Boot 3.0.5版本、MySQL数据库环境下,使用以下配置尝试将ddl-auto设为none时,实际生效的配置却是create:

    spring:
      security.debug: false
      jpa:
        properties:
          hibernate:
            show_sql: true
            format_sql: true
            use_sql_comments: true
        hibernate:
          ddl-auto: none
    
  • 有效配置方案:
    将配置调整为直接使用Hibernate原生属性hbm2ddl.auto后,none设置可以正常生效:

    spring:
      security.debug: false
      jpa:
        properties:
          hibernate:
            hbm2ddl:
              auto: none
            show_sql: true
            format_sql: true
            use_sql_comments: true
    
  • 原因分析:
    Spring Boot 3.0.x对Hibernate配置的映射逻辑存在优先级问题:

    1. spring.jpa.hibernate.ddl-auto是Spring Boot封装的配置项,当同时在spring.jpa.properties.hibernate下配置其他Hibernate属性时,自动配置流程中可能出现属性覆盖,导致原本设置的none被替换为create。
    2. hibernate.hbm2ddl.auto是Hibernate的原生配置属性,通过spring.jpa.properties.hibernate.hbm2ddl.auto配置时,会直接传递给Hibernate内核,不受Spring Boot封装层的配置冲突影响,因此能准确生效。
    3. 尽管ddl-auto的默认值为none,但HibernateProperties.setDdlAuto方法传入值为create,这进一步验证了配置层级间的覆盖问题。

内容的提问来源于stack exchange,提问作者leeseokwoon

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 17:00:07