0

I started to learn spring boot and now currently working on a simple authentication project. But I have a problem. Database is always initialized. I configure application properties like this.

spring.datasource.initialization-mode=never
spring.jpa.open-in-view=false
spring.thymeleaf.cache=false

I set initialization-model "never". But it does not work. Db is consist of two tables: users and roles. Of course users and roles has ManyToMany relation and has user_role table.

public class User {

//...

@ManyToMany(cascade=CascadeType.ALL)
    @JoinTable(name="user_role", joinColumns = @JoinColumn(name="user_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name="role_id" , referencedColumnName = "role_id"))
    private Set<Role> roles;
}

What could be a problem?

2
  • Can you share more details. Property you added is correct and should work. Is it causing you any failure or anything else?? If error is there you can use property -> spring.datasource.continue-on-error=true Commented Dec 7, 2019 at 12:49
  • more details would be appreciated. Commented Dec 7, 2019 at 12:49

2 Answers 2

1

Assuming you're using spring-data-jpa, you could set the following property:

spring.jpa.hibernate.ddl-auto

The possible values are: create, create-drop, validate, and update.

On your case, it would be better set update.

Sign up to request clarification or add additional context in comments.

Comments

0

If you do not want spring-boot to a reinitialize your db, then you should use the property spring.jpa.generate-ddl=false

1 Comment

Thank for your answer. But it does not work for me. I configure spring.jpa.generate-ddl=false. But data in db always be cleared when restart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.