【问题标题】:Hibernate does not drop H2 Database when FK exist当 FK 存在时,Hibernate 不会删除 H2 数据库
【发布时间】:2020-02-10 11:45:36
【问题描述】:

H2Dialect.dropConstraints 有评论

// We don't need to drop constraints before dropping tables, that just leads to error
// messages about missing tables when we don't have a schema in the database

但这似乎是错误的,当我的下一个单元测试类从自定义属性集开始时

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
        "aaa=bbb"})

创建了一个新的上下文,Hibernate 尝试删除模式以重新创建它。这会导致约束异常:

Cannot drop "XXX" because "FK_XXX, FK_XXX, FK_XXX, FK_XXX" depends on it; SQL statement:

    drop table xxx if exists [90107-200]

为什么 H2Dialect 不能正确删除约束?

【问题讨论】:

    标签: hibernate h2 ddl


    【解决方案1】:

    H2 1.4.200 比早期版本更符合 SQL 标准,并且 Hibernate 还不真正支持该版本中的更改,但是有一个针对 H2Dialect 的修复的拉取请求(我没有测试它) :#3093。您可以尝试使用具有类似变化的自己的方言。

    另见HHH-13711

    【讨论】:

      猜你喜欢
      • 2018-06-12
      • 2021-03-02
      • 2022-11-13
      • 1970-01-01
      • 2013-05-01
      • 1970-01-01
      • 2018-05-01
      • 2011-04-11
      • 2012-09-21
      相关资源
      最近更新 更多