【问题标题】:Function "IDENTITY" not found when inserting audited revision using Hibernate Envers (5.6.10) with Spring Boot 2.7 (H2 2.1.214, Hibernate-core 5.6.9)使用带有 Spring Boot 2.7(H2 2.1.214、Hibernate-core 5.6.9)的 Hibernate Envers (5.6.10) 插入审核修订时未找到函数“IDENTITY”
【发布时间】:2022-09-27 19:59:18
【问题描述】:

插入经过审核的修订时,出现以下错误:

Hibernate: insert into audited_revision (id, timestamp) values (default, ?)
2022-07-21 15:46:09.496 TRACE 67111 --- [  XNIO-1 task-1] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [TIMESTAMP] - [Thu Jul 21 15:46:09 CEST 2022]
Hibernate: call identity()
2022-07-21 15:46:09.504  WARN 67111 --- [  XNIO-1 task-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 90022, SQLState: 90022
2022-07-21 15:46:09.504 ERROR 67111 --- [  XNIO-1 task-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : Function \"IDENTITY\" not found; SQL statement:
call identity() [90022-214]
2022-07-21 15:46:09.518 ERROR 67111 --- [  XNIO-1 task-1] o.z.problem.spring.common.AdviceTraits   : Internal Server Error

org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [call identity()]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement

根据 Hibernate Jira 上的这个问题,它应该在 Hibernate 核心 5.6.5 中得到修复。 https://hibernate.atlassian.net/browse/HHH-14985 我目前正在使用 Spring Boot 2.7.2 提供的 Hibernate core 5.6.9,但仍然遇到上述问题。该列是根据这段日志正确创建的:

Hibernate: create table audited_revision (id bigint generated by default as identity, timestamp timestamp, primary key (id))

我相关的 application.yaml 配置:

spring:
  jpa:
    defer-datasource-initialization: true
    database: H2
    hibernate:
      ddl-auto: create-drop
    open-in-view: false
    properties:
      format_sql: true
      org:
        hibernate:
          envers:
            store_data_at_delete: true
      hibernate:
        temp:
          use_jdbc_metadata_defaults: false
        dialect: org.hibernate.dialect.H2Dialect
    show-sql: true

这是休眠中的错误还是我做错了什么?

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


    【解决方案1】:

    在数据库连接中添加MODE=LEGACY;

    例如application.yml:

    spring:
      datasource:
        url: jdbc:h2:mem:test;MODE=LEGACY;
    

    示例 application.properties:

    spring.datasource.url=jdbc:h2:mem:test;MODE=LEGACY;
    

    【讨论】:

      猜你喜欢
      • 2015-09-20
      • 2011-07-07
      • 2021-09-03
      • 2017-07-09
      • 2014-06-21
      • 2023-03-24
      • 2019-08-20
      • 1970-01-01
      • 2012-10-25
      相关资源
      最近更新 更多