【问题标题】:JPA database indexes are not working properly in latest H2 (2.0.204)JPA 数据库索引在最新的 H2 (2.0.204) 中无法正常工作
【发布时间】:2022-01-26 17:55:07
【问题描述】:

我正在尝试将 H2 版本从 1.4.200 升级到 2.0.204。但是,在我看来,索引无法正常工作。

步骤:

  1. 从 JPA 层创建实体和索引,如下图所示。 SomeEntity.Java example

2。 application.properties 中的默认值:

    spring.datasource.url=jdbc:h2:file:./data/testDb
    spring.datasource.driverClassName=org.h2.Driver
    spring.datasource.username=sa
    spring.datasource.password=
    spring.jpa.show-sql=true
    spring.jpa.hibernate.ddl-auto=update
    spring.jpa.open-in-view=false
    spring.h2.console.enabled=true
    spring.h2.conso\le.path=/h2
  1. 启动 spring-boot 应用程序。

到这一步,一切正常,索引创建成功。

  1. 现在,重新启动服务。

这里,H2 服务(尤其是,"CreateIndex.executeMeta") 再次尝试创建索引(自定义索引)失败了。

以上步骤在旧版本(1.4.200 及以下)中运行良好。

有人遇到过类似的问题,或者我们有什么解决方法吗? 谢谢!!

【问题讨论】:

    标签: spring-boot hibernate jpa spring-data-jpa h2


    【解决方案1】:

    在 2.0 版中,H2 发生了重大变化。使用旧版兼容模式可以将部分更改的行为改回:http://www.h2database.com/html/features.html

    请尝试设置

    spring.datasource.url=jdbc:h2:file:./data/testDb;MODE=LEGACY
    

    如果这没有帮助,您可能需要等待升级,直到发布兼容的 Hibernate 版本。参见例如:

    【讨论】:

    • 是的,我向 H2database 团队提出了这个问题,他们知道这个问题:github.com/h2database/h2database/issues/3310 不幸的是,我需要等到那时。
    • 另外,";MODE=LEGACY" 也无济于事,因为问题出在 hibernate builder 中。
    猜你喜欢
    • 1970-01-01
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多