5

What is the difference between spring.jpa.hibernate.hbm2ddl and spring.jpa.hibernate.ddl?

I have found in this question: What are the possible values of spring.datasource.initialization-mode? that OP is using both in properties, however it seems like the origin of hbm2ddl is hibernate directly not Spring Data Jpa.

Nevertheless, reading the answer from another OP, it looks like pass-through only.

However in our commercial project with mariadb, when we do not close our spring boot application gracefully with spring.jpa.hibernate.hbm2ddl.auto=create, when the application is run again, it deletes old data and creates everything from scratch. On the other hand with spring.jpa.hibernate.ddl.auto=create every second run (after no graceful application shutdown) causes key constraint exceptions (DB is not being dropper before creation)

1 Answers1

0
  1. From this Link
  • By default, JPA databases are automatically created only if you use an embedded database (H2, HSQL, or Derby).

You can explicitly configure JPA settings by using spring.jpa.* properties. For example, to create and drop tables you can add the following line to your application.properties:

spring.jpa.hibernate.ddl-auto=create-drop

Hibernate’s own internal property name for this (if you happen to remember it better) is hibernate.hbm2ddl.auto.

  1. From this Link

spring.jpa.hibernate.ddl-auto This is actually a shortcut for the "hibernate.hbm2ddl.auto" property.

Defaults to "create-drop" when using an embedded database and no schema manager was detected. Otherwise, defaults to "none".

  1. From this Link
  • Spring Boot can automatically create the schema (DDL scripts) of your DataSource and initialize it (DML scripts).

  • It loads SQL from the standard root classpath locations: schema.sql and data.sql, respectively.

  • In addition, Spring Boot processes the schema-${platform}.sql and data-${platform}.sql files (if present), where platform is the value of spring.datasource.platform.

  • This allows you to switch to database-specific scripts if necessary. For example, you might choose to set it to the vendor name of the database (hsqldb, h2, oracle, mysql, postgresql, and so on).

YourAboutMeIsBlank
  • 1,787
  • 3
  • 18
  • 27