0

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?

Amos Machora
  • 486
  • 3
  • 12
  • 1
    Hi @AmohPrince Please have a look of this link https://stackoverflow.com/questions/21113154/spring-boot-ddl-auto-generator https://stackoverflow.com/questions/221379/hibernate-hbm2ddl-auto-update-in-production – Raushan Kumar Feb 11 '22 at 18:28
  • Spring doesn't by itself. You are probably taking about one of the persistence solutions, like JPA (or JDCBTemplate, or other). – The Impaler Feb 11 '22 at 18:34

1 Answers1

1

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
Dharman
  • 30,962
  • 25
  • 85
  • 135
Rafa
  • 467
  • 4
  • 18