Spring Boot 3.0.5 is in use. I set ddl-auto as follows, but ddl-auto is set to create.

spring:
  security.debug: false
  jpa:
    properties:
      hibernate:
        show_sql: true
        format_sql: true
        use_sql_comments: true
    hibernate:
      ddl-auto: none

However, if you change the settings as follows, it will work fine.

spring:
  security.debug: false
  jpa:
    properties:
      hibernate:
        hbm2ddl:
          auto: none
        show_sql: true
        format_sql: true
        use_sql_comments: true

Comment From: wilkinsona

I cannot reproduce the behavior that you have described. Here's the log output from a minimal application using your first set of configuration properties:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.5)

2023-06-06T11:30:19.819+01:00  INFO 81090 --- [           main] com.example.demo.Gh35757Application      : Starting Gh35757Application using Java 17.0.4.1 with PID 81090 (/Users/awilkinson/dev/workspaces/spring-projects/spring-boot/main/gh-35757/target/classes started by awilkinson in /Users/awilkinson/dev/workspaces/spring-projects/spring-boot/main/gh-35757)
2023-06-06T11:30:19.822+01:00  INFO 81090 --- [           main] com.example.demo.Gh35757Application      : No active profile set, falling back to 1 default profile: "default"
2023-06-06T11:30:20.109+01:00  INFO 81090 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-06-06T11:30:20.122+01:00  INFO 81090 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7 ms. Found 0 JPA repository interfaces.
2023-06-06T11:30:20.360+01:00  INFO 81090 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-06-06T11:30:20.392+01:00  INFO 81090 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.1.7.Final
2023-06-06T11:30:20.569+01:00  INFO 81090 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-06-06T11:30:20.701+01:00  INFO 81090 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:505a3c45-3804-42ef-bc23-4c7c169f069e user=SA
2023-06-06T11:30:20.702+01:00  INFO 81090 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-06-06T11:30:20.723+01:00  INFO 81090 --- [           main] SQL dialect                              : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2023-06-06T11:30:21.215+01:00  INFO 81090 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-06-06T11:30:21.221+01:00  INFO 81090 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-06-06T11:30:21.311+01:00  INFO 81090 --- [           main] com.example.demo.Gh35757Application      : Started Gh35757Application in 1.848 seconds (process running for 2.18)
2023-06-06T11:30:21.315+01:00  INFO 81090 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2023-06-06T11:30:21.316+01:00  INFO 81090 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2023-06-06T11:30:21.318+01:00  INFO 81090 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

If I change the properties to remove the ddl-auto setting, create-drop is used:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.5)

2023-06-06T11:31:39.924+01:00  INFO 81826 --- [           main] com.example.demo.Gh35757Application      : Starting Gh35757Application using Java 17.0.4.1 with PID 81826 (/Users/awilkinson/dev/workspaces/spring-projects/spring-boot/main/gh-35757/target/classes started by awilkinson in /Users/awilkinson/dev/workspaces/spring-projects/spring-boot/main/gh-35757)
2023-06-06T11:31:39.928+01:00  INFO 81826 --- [           main] com.example.demo.Gh35757Application      : No active profile set, falling back to 1 default profile: "default"
2023-06-06T11:31:40.224+01:00  INFO 81826 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-06-06T11:31:40.238+01:00  INFO 81826 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 9 ms. Found 0 JPA repository interfaces.
2023-06-06T11:31:40.473+01:00  INFO 81826 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-06-06T11:31:40.613+01:00  INFO 81826 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection conn0: url=jdbc:h2:mem:a4e718a6-ec2b-4fd7-ba25-0c0156201b42 user=SA
2023-06-06T11:31:40.614+01:00  INFO 81826 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-06-06T11:31:40.651+01:00  INFO 81826 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-06-06T11:31:40.685+01:00  INFO 81826 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.1.7.Final
2023-06-06T11:31:40.892+01:00  INFO 81826 --- [           main] SQL dialect                              : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Hibernate: 

    drop table if exists city cascade 
Hibernate: 

    drop sequence if exists city_seq
Hibernate: create sequence city_seq start with 1 increment by 50
Hibernate: 

    create table city (
       id bigint not null,
        country varchar(255) not null,
        map varchar(255) not null,
        name varchar(255) not null,
        state varchar(255) not null,
        primary key (id)
    )
2023-06-06T11:31:41.394+01:00  INFO 81826 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-06-06T11:31:41.400+01:00  INFO 81826 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-06-06T11:31:41.488+01:00  INFO 81826 --- [           main] com.example.demo.Gh35757Application      : Started Gh35757Application in 2.046 seconds (process running for 2.402)
2023-06-06T11:31:41.492+01:00  INFO 81826 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2023-06-06T11:31:41.493+01:00  INFO 81826 --- [ionShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Hibernate: 

    drop table if exists city cascade 
Hibernate: 

    drop sequence if exists city_seq
2023-06-06T11:31:41.495+01:00  INFO 81826 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2023-06-06T11:31:41.497+01:00  INFO 81826 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

but ddl-auto is set to create

The default with an embedded database is create-drop. With an external database its none. If create is being used, I suspect that spring.jpa.hibernate.ddl-auto is being set to create from a source that has priority over application.yaml such as an environment variable or system property. This would also explain why your second set of configuration properties works as when both spring.jpa.properties.hibernate.hbm2ddl and spring.jap.hibernate.ddl-auto are set, the former takes precedence.

If you do not think that the above applies and you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: lso5507

hello @wilkinsona, thank you for comment

I'm using the Mysql database, so I don't expect the default for ddl-auto to be create-drop. The following is the log when you apply the ddl-auto setting to the yaml file. As you can see in the log, the table is being dropped, so I think the ddl-auto value is set to create.


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.5)

2023-06-06T19:40:12.076+09:00  INFO 65553 --- [           main] c.t.main.TripbookMainApiApplication      : Starting TripbookMainApiApplication using Java 19.0.1 with PID 65553 (/Users/leeseokwoon/Documents/GitHub/tripbook-main-api/target/classes started by leeseokwoon in /Users/leeseokwoon/Documents/GitHub/tripbook-main-api)
2023-06-06T19:40:12.080+09:00  INFO 65553 --- [           main] c.t.main.TripbookMainApiApplication      : The following 1 profile is active: "local"
2023-06-06T19:40:13.882+09:00  INFO 65553 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-06-06T19:40:13.982+09:00  INFO 65553 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 94 ms. Found 3 JPA repository interfaces.
2023-06-06T19:40:14.691+09:00  INFO 65553 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9000 (http)
2023-06-06T19:40:14.697+09:00  INFO 65553 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-06-06T19:40:14.698+09:00  INFO 65553 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.7]
2023-06-06T19:40:14.841+09:00  INFO 65553 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-06-06T19:40:14.841+09:00  INFO 65553 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2683 ms
2023-06-06T19:40:20.149+09:00  INFO 65553 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-06-06T19:40:20.179+09:00  INFO 65553 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.1.7.Final
2023-06-06T19:40:20.355+09:00  INFO 65553 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-06-06T19:40:20.876+09:00  INFO 65553 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@283e1759
2023-06-06T19:40:20.879+09:00  INFO 65553 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-06-06T19:40:20.952+09:00  INFO 65553 --- [           main] SQL dialect                              : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Hibernate: 

    alter table tb_bookmark 
       drop 
       foreign key FKljw2jq9jo7kl0asf7twnb5tbg
Hibernate: 

    alter table tb_giftshop 
       drop 
       foreign key FK9m1des8a3plfixs2d4bukxdol
Hibernate: 

    alter table tb_inquiry 
       drop 
       foreign key FKf07ui0p5p97iempi3ghy1kj52
Hibernate: 

    alter table tb_jwttk 
       drop 
       foreign key FKp5uocksn6376h0dld0ose6uhl
Hibernate: 

    alter table tb_member_grade 
       drop 
       foreign key FKpfy574x0pjqgq764wt545v6wm
Hibernate: 

    alter table tb_member_status 
       drop 
       foreign key FKndn9xy2g3hs04xq52ifs5x754
Hibernate: 

    alter table tb_rollbook 
       drop 
       foreign key FKs5vmwphklc3792t4qb7u57hui
Hibernate: 

    alter table tb_survey 
       drop 
       foreign key FKrxd3h56cvg5shv38e3lats4c7
Hibernate: 

    drop table if exists tb_bookmark
Hibernate: 

    drop table if exists tb_giftshop
Hibernate: 

    drop table if exists tb_inquiry
Hibernate: 

    drop table if exists tb_jwttk

I also found that the HibernateProperties class takes the value of the ddlAuto field to create, is this not relevant? Thank you for reading awkward English.

Comment From: wilkinsona

I also found that the HibernateProperties class takes the value of the ddlAuto field to create, is this not relevant?

That further suggests that your YAML is being overridden by some other configuration such as an environment variable or system property. If you add Actuator to your application, the env endpoint will tell you the origin of the ddl-auto property's value.

As I said above, if this doesn't help and you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.