Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot ddl auto generator

I'm using spring boot with spring.jpa.hibernate.ddl-auto=create, but when application restarted, all tables drops and creates again. Is there some way to avoiding re-creation for already existing tables?

like image 239
gorill Avatar asked Jan 14 '14 12:01

gorill


People also ask

What is DDL-Auto in spring boot?

ddl-auto explicitly and the standard Hibernate property values are none , validate , update , create , and create-drop . Spring Boot chooses a default value for you based on whether it thinks your database is embedded. It defaults to create-drop if no schema manager has been detected or none in all other cases.

How does auto DDL work?

ddl-auto= create-drop" means that when the server is run, the database(table) instance is created. And whenever the server stops, the database table instance is droped.

What is generate DDL in JPA?

JPA has features for DDL generation, and these can be set up to run on startup against the database. This is controlled through two external properties: spring. jpa. generate-ddl (boolean) switches the feature on and off and is vendor independent.


2 Answers

The list of option which is used in the spring boot are

  • validate: validate the schema, makes no changes to the database.
  • update: update the schema.
  • create: creates the schema, destroying previous data.
  • create-drop: drop the schema at the end of the session
  • none: is all other cases.

So for avoiding the data lose you use update

like image 89
sudar Avatar answered Sep 20 '22 15:09

sudar


spring.jpa.hibernate.ddl-auto=update 

hibernate.ddl-auto should usually not be used in production.

like image 23
samlewis Avatar answered Sep 19 '22 15:09

samlewis