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?
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.
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.
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.
The list of option which is used in the spring boot are
So for avoiding the data lose you use update
spring.jpa.hibernate.ddl-auto=update
hibernate.ddl-auto should usually not be used in production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With