Working with application.properties file

Asked

Viewed 3,090 times

2

See my application.. properties file:

 spring.jpa.database=POSTGRESQL
  spring.datasource.platform=postgres
  spring.jpa.show-sql=true
  spring.jpa.hibernate.ddl-auto=create-drop
  spring.database.driverClassName=org.postgresql.Driver
  spring.datasource.url=jdbc:postgresql://localhost:5432/money?createDatabaseIfNotExist=true&useSSL=false
  spring.datasource.username=postgres
  spring.datasource.password=1234

What’s happening is that every time I run the project it drops into the table and then creates the table all over again, and with that it erases all the records that exist in the database as you can see below;

This below is a log of Springtools, it is because my project is a Spring Boot

Hibernate: drop table if exists categoria cascade
Hibernate: create table categoria (codigo  bigserial not null, nome varchar(255), primary key (codigo))
[2m2017-11-14 13:24:14.127[0;39m [32m INFO[0;39m [35m4076[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36morg.hibernate.tool.hbm2ddl.SchemaExport [0;39m [2m:[0;39m HHH000230: Schema export complete

How do I set up the file not to do this?

I tried with this piece of code, but I was unsuccessful.

?createDatabaseIfNotExist=true&useSSL=false

2 answers

2


Hello, this property should not be at this value:

 spring.jpa.hibernate.ddl-auto=create-drop

In this case it will always "drop" the table and recreate. I recommend if you want to keep the data remove this property from your properties(comment)

-1

You can also use another setting in this line of code. For example:

spring.jpa.hibernate.ddl-auto=update

This way the data is stored and you only update tables and fields that suffer some change.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.