Hibernate : Why is it trying to drop/create database on startup?
Asked Answered
G

5

13

I'm new with Spring. I finally succeeded to build my application with no error but when i'm looking to the output i have a lot of information that i don't understand.

First this error each tables, it seems to be a Hibernate/Spring bug :

Hibernate: alter table entity.administrationaction drop constraint FKjaafjywumaavhae5kjyo34gx5
        2016-11-13 12:16:41.475 ERROR 2156 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table entity.administrationaction drop constraint FKjaafjywumaavhae5kjyo34gx5
        2016-11-13 12:16:41.475 ERROR 2156 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : ERREUR: la relation « entity.administrationaction » n'existe pas 

Then this for each table :

Hibernate: drop table if exists entity.administrationaction cascade

Then this for each table :

Hibernate: create table entity.administrationaction (id  serial not null, action int4, creation_date timestamp, entity_class varchar(255), entity_id int4, message varchar(255), administrator_id int4, primary key (id))

So it is like Spring was trying to drop all my database and recreate it. Why ? Is it normal or have i done something wrong ?

Guileless answered 13/11, 2016 at 11:35 Comment(1)
Perhaps you want to post a Minimal, Complete, and Verifiable version of your code, so that others have chance to point you in the right direction.Abiding
I
36

Place in application.properties/application.yml

spring.jpa.hibernate.ddl-auto=update

This property can be set with values

1. update (Update the schema if necessary)
2. create (create the schema and destroy previous data)
3. create-drop (create and then destroy the schema at the end of the session)
4. none (disable ddl handling)
5. validate (validate the schema , make no changes to the database)
Interfaith answered 13/11, 2016 at 11:57 Comment(0)
I
7

Look for the hibernate.hbm2ddl.auto setting. Probably you have set it to create-drop.

Infirmary answered 13/11, 2016 at 11:50 Comment(1)
Thanks man it was it ... That what happenned when you take code from someone else and read it too fast : my bad :/Guileless
D
3

Some additional information as I found myself here not understanding why Spring would default to create-drop:

spring.jpa.hibernate.ddl-auto String: DDL mode. This is actually a shortcut for the "hibernate.hbm2ddl.auto" property. Defaults to "create-drop" when using an embedded database and no schema manager was detected. Otherwise, defaults to "none".

Source: Javadoc

Diapause answered 13/8, 2020 at 13:4 Comment(0)
T
0
spring.jpa.hibernate.ddl-auto=none

this worked for me and it didn't messed up with the table and just used it.

Toogood answered 10/1, 2019 at 16:49 Comment(0)
R
0
spring.jpa.hibernate.ddl-auto=validate

add this line in applications.properties file. This worked for me.

Repugnance answered 4/5, 2022 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.