Disable table recreation in Spring Boot application
Your configuration isn't a @Configuration
class.
Next to that I suggest that you use the power of Spring Boot. Which means I would suggest removing everything but the DataSource
configuration and simply add an application.properties file with the following properties
spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=update
This should give you the desired behavior, with less coding.
You could even remove the datasource if you have either commons-dbcp or tomcat-pool in your classpath and adding the following properties
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost/mydatabase
spring.datasource.username=myusername
spring.datasource.password=mypassword
If you are using spring boot, you could do it by configuration over the config file. Hibernate has all this possibilities:
- validate (validate the schema)
- update (update the schema if are changes)
- create (create the schema)
- create-drop (create the schema and drop it at the end)
but if you want don't do anything, spring boot add other chance, use as follow:
spring:
jpa:
hibernate:
ddl-auto: none