Hibernate:为什么在启动时尝试删除/创建数据库?

Ant*_*ine 4 java spring hibernate spring-mvc

我是Spring的新手.我终于成功地构建了我的应用程序,没有错误,但是当我正在寻找输出时,我有很多我不理解的信息.

首先这个错误每个表,它似乎是一个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 
Run Code Online (Sandbox Code Playgroud)

然后为每个表格:

Hibernate: drop table if exists entity.administrationaction cascade
Run Code Online (Sandbox Code Playgroud)

然后为每个表格:

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))
Run Code Online (Sandbox Code Playgroud)

所以就像Spring试图删除我的所有数据库并重新创建它一样.为什么?这是正常的还是我做错了什么?

Nir*_*mar 14

放在application.properties/application.yml中

spring.jpa.hibernate.ddl-AUTO =更新

可以使用值设置此属性

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)
Run Code Online (Sandbox Code Playgroud)


Pet*_*hev 6

寻找hibernate.hbm2ddl.auto设置。可能您已将其设置为create-drop.