'Hibernate : Why is it trying to drop/create database on startup?

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 ?



Solution 1:[1]

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)

Solution 2:[2]

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

Solution 3:[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

Solution 4:[4]

spring.jpa.hibernate.ddl-auto=none

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

Solution 5:[5]

spring.jpa.hibernate.ddl-auto=validate

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Niranjan Kumar
Solution 2 Petar Minchev
Solution 3 Didier Breedt
Solution 4 Arunkumar Arjunan
Solution 5 Praniket More