What are the possible values of the Hibernate hbm2ddl.auto configuration and what do they do

前端 未结 13 2428
轮回少年
轮回少年 2020-11-21 04:47

I really want to know more about the update, export and the values that could be given to hibernate.hbm2ddl.auto
I need to know when to use the update and w

13条回答
  •  灰色年华
    2020-11-21 05:25

    Since this is a very common question, this answer is based on an article I wrote on my blog.

    First, the possible values for the hbm2ddl configuration property are the following ones:

    • none - No action is performed. The schema will not be generated.
    • create-only - The database schema will be generated.
    • drop - The database schema will be dropped.
    • create - The database schema will be dropped and created afterward.
    • create-drop - The database schema will be dropped and created afterward. Upon closing the SessionFactory, the database schema will be dropped.
    • validate - The database schema will be validated using the entity mappings.
    • update - The database schema will be updated by comparing the existing database schema with the entity mappings.

    I dedicated a blog post for the most common Hibernate DDL generation strategies:

    1. The hibernate.hbm2ddl.auto="update" is convenient but less flexible if you plan on adding functions or executing some custom scripts.
    2. The most flexible approach is to use Flyway.

    However, even if you use Flyway, you can still generate the initial migration script using hbm2ddl. In this article, you can see how you can combine the JPA Entity Model with jOOQ Table Model.

提交回复
热议问题