Issue
When inserting an audited revision I get the following error:
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
According to this issue on the Hibernate Jira it is supposed to be fixed in Hibernate core 5.6.5. https://hibernate.atlassian.net/browse/HHH-14985 I'm currently using Hibernate core 5.6.9 provided by Spring Boot 2.7.2 and I still get the above issue. The column is correctly created according to this piece of logging:
Hibernate: create table audited_revision (id bigint generated by default as identity, timestamp timestamp, primary key (id))
My relevant piece of application.yaml config:
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
Is this a bug in Hibernate or am I doing something wrong?
Solution
This issue is fixed in Hibernate core 5.6.13
https://hibernate.atlassian.net/browse/HHH-15561
Answered By - SANN3
Answer Checked By - David Marino (JavaFixing Volunteer)