Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 741
Antoine Avatar asked Nov 13 '16 11:11

Antoine


2 Answers

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)
like image 184
Niranjan Kumar Avatar answered Sep 18 '22 09:09

Niranjan Kumar


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

like image 22
Petar Minchev Avatar answered Sep 18 '22 09:09

Petar Minchev