【问题标题】:Hibernate : Why is it trying to drop/create database on startup?Hibernate:为什么它试图在启动时删除/创建数据库?
【发布时间】:2017-03-27 04:20:52
【问题描述】:

我是 Spring 新手。我终于成功地构建了我的应用程序,没有错误,但是当我查看输出时,我有很多我不明白的信息。

首先这个错误每个表,它似乎是一个Hibernate/Spring错误:

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 

然后每个表都这样:

Hibernate: drop table if exists entity.administrationaction cascade

然后每个表都这样:

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))

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

【问题讨论】:

标签: java spring hibernate spring-mvc


【解决方案1】:

我在这里发现自己不理解为什么 Spring 会默认为 create-drop 的一些附加信息:

spring.jpa.hibernate.ddl-autoString: DDL 模式。这实际上是“hibernate.hbm2ddl.auto”属性的快捷方式。使用嵌入式数据库且未检测到模式管理器时默认为“create-drop”。否则,默认为“无”。

来源:Javadoc

【讨论】:

    【解决方案2】:
    spring.jpa.hibernate.ddl-auto=none
    

    这对我有用,它并没有把桌子弄乱,只是使用它。

    【讨论】:

      【解决方案3】:

      放在application.properties/application.yml中

      spring.jpa.hibernate.ddl-auto=update

      这个属性可以设置值

      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)
      

      【讨论】:

        【解决方案4】:

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

        【讨论】:

        • 谢谢,就是这样......当你从别人那里获取代码并读得太快时发生的事情:我的错:/
        猜你喜欢
        • 2014-08-29
        • 2021-04-04
        • 1970-01-01
        • 1970-01-01
        • 2020-02-20
        • 1970-01-01
        • 2014-01-30
        • 1970-01-01
        • 2015-01-28
        相关资源
        最近更新 更多