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
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:
hibernate.hbm2ddl.auto="update"
is convenient but less flexible if you plan on adding functions or executing some custom scripts.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.