spring-data-jpa 使用Hibernate Envers(5.6.10)和Sping Boot 2.7(H2 2.1.214,Hibernate核心5.6.9)插入已审核修订时,未找到函数“IDENTITY”

tcomlyy6  于 2022-11-10  发布在  Spring
关注(0)|答案(2)|浏览(141)

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

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 core 5.6.5. https://hibernate.atlassian.net/browse/HHH-14985中修复。我目前使用的是Sping 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))

我的相关应用程序。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

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

qqrboqgw

qqrboqgw1#

在数据库连接中添加MODE=LEGACY;
实施例application.yml

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

application.properties:

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

相关问题