Home > Enterprise >  How does spring create and update databases?
How does spring create and update databases?

Time:02-12

I've seen this line of code

spring.jpa.hibernate.ddl-auto=none

in multiple spring tutorials. My question is for example in a production scenario I want my app to create a database for the first time in the client machine then keep using the database and not keep recreating a new database each time it is run. How can I achieve this? and what does the above code really mean?

CodePudding user response:

To achive this you dont have to do anything. Just inside the application.properties file add:

spring.datasource.url=jdbc:mysql://localhost:3306/db_name
spring.datasource.username=root
spring.datasource.password=password

The rest is handled by JPA.

Sometimes we may need to run our own sql scripts on application's startup by using data.sql or schema.sql files. In this situation we have to disable Hibernate automatic schema creation by adding the following inside the application.properties file.

spring.jpa.hibernate.ddl-auto=none
  • Related