0

Basically the same question than here

When I try the solution (adding spring.jpa.hibernate.ddl-auto=validate to the properties file) I get a missing table error (because the database is empty).

I tried spring.jpa.hibernate.ddl-auto=update, but it doesn't load the data neither.

Is there any way to tell Spring that create a database and don't drop it?

Community
  • 1
  • 1
Zucca
  • 561
  • 1
  • 7
  • 21

1 Answers1

0

Create your DB structure yourself, and use validate.

Michał Zaborowski
  • 3,911
  • 2
  • 19
  • 39
  • I know I can do this, but I am just asking id there is a way to have it automatically built (there should be a way). – Zucca Jan 10 '17 at 12:40
  • You mean - create if not exists? What if you have different structure? Basically there are two options - hibernate do it for you, by creating, and deleting, or you decide to do that yourself. There are tools like flyway, but still that is not done out of the box. – Michał Zaborowski Jan 10 '17 at 12:42
  • This only happens to me when I use an embebbed database, if I use for example a MySQL database, when I set `hibernate.hbm2ddl.auto=update` I get the behavior I expect (create if doesn't exist and then update the next time) – Zucca Jan 10 '17 at 12:48
  • Yes, for other DBs that goes like expected. You can try with `create` instead of `update`. Note that `create-drop` is default option here. – Michał Zaborowski Jan 10 '17 at 12:50
  • Edit: create does maintain the structure and it destroys the data, but when I change it to validate, it stills hitting me `missing table error`. – Zucca Jan 10 '17 at 12:58
  • 1
    I had issues like that, with H2. That was only used to run integration testing, on local env. so create-drop was kind of advantage, but not always... Generate DDL from your model, and use it to init DB. – Michał Zaborowski Jan 10 '17 at 13:01