[JIRA] (HHH-15777) wrong column type expected for audit table keys
by Pete Nattress (JIRA)
Pete Nattress ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HHH-15777 ( https://hibernate.atlassian.net/browse/HHH-15777?atlOrigin=eyJpIjoiZGQ0MW... )
Re: wrong column type expected for audit table keys ( https://hibernate.atlassian.net/browse/HHH-15777?atlOrigin=eyJpIjoiZGQ0MW... )
Hi, I’ve encountered a similar problem also doing a Spring Boot 2.7 → 3.0 upgrade. We have entities with Instant fields which are mapped to DATE columns in our Oracle DB. As of Hibernate 6 the default mapping for Instant is to TIMESTAMP WITH TIME ZONE columns, but this default can be overridden by setting hibernate.type.preferred_instant_jdbc_type=TIMESTAMP. However it appears that envers doesn’t recognise this option, and adding a @JdbcType or @JdbcTypeCode annotation explicitly on the entity fields doesn’t work either.
This results in errors like this when inserting audit records:
Caused by: org.hibernate.exception.GenericJDBCException: could not insert: [uk.co.mycompany.MyEntity_AUD]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:61)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3447)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:4058)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:103)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:612)
at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:483)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:480)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:329)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1425)
... 194 common frames omitted
Caused by: java.sql.SQLException: Invalid column type: 2014
at oracle.jdbc.driver.OracleStatement.getInternalType(OracleStatement.java:4369)
at oracle.jdbc.driver.OraclePreparedStatement.setNullCritical(OraclePreparedStatement.java:5836)
at oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStatement.java:5818)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setNull(OraclePreparedStatementWrapper.java:1292)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setNull(HikariProxyPreparedStatement.java)
at org.hibernate.type.descriptor.jdbc.BasicBinder.doBindNull(BasicBinder.java:100)
at org.hibernate.type.descriptor.jdbc.BasicBinder.bind(BasicBinder.java:53)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:221)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:217)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:34)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:3237)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3420)
... 204 common frames omitted
For me there’s a simple workaround of creating an AttributeConverter to explicitly define the mapping behaviour I want, which envers does pick up and apply to its generated entity definitions (you can see this in the envers HBM dump where the field type is marked as converted:: ). But I’d expect all of the type mapping logic which applies to the entity class to be applied to the audit entity in a consistent way.
( https://hibernate.atlassian.net/browse/HHH-15777#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-15777#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100214- sha1:b03f6a4 )
1 year, 12 months