[JIRA] (HHH-15777) envers 3.0.0 expects the wrong column type for audit table keys
by Donal Murtagh (JIRA)
Donal Murtagh ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYTFjYzIwMmVk... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-15777?atlOrigin=eyJpIjoiYTFjYz... ) HHH-15777 ( https://hibernate.atlassian.net/browse/HHH-15777?atlOrigin=eyJpIjoiYTFjYz... ) envers 3.0.0 expects the wrong column type for audit table keys ( https://hibernate.atlassian.net/browse/HHH-15777?atlOrigin=eyJpIjoiYTFjYz... )
Issue Type: Bug Affects Versions: 6.1.5 Assignee: Chris Cranford ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) Components: hibernate-envers Created: 28/Nov/2022 07:50 AM Priority: Major Reporter: Donal Murtagh ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3... )
*Note* : I originally reported this issue to the spring-data-jpa project ( https://github.com/spring-projects/spring-data-jpa/issues/2712 ) , but they have concluded it’s a problem with Hibernate/Hibernate Envers.
While upgrading a Spring Boot app from v2.7.5 to v3.0.0, I upgraded the spring-data-envers starter to v3.0.0. The relevant section of the Gradle dependency report is shown at the end of this issue.
In my entity classes, the primary keys are UUIDs. The column type for these keys are varachar(255). Prior to the upgrade, these were defined as follows
@Audited
@Entity
@Table(name = "foo" )
public class Foo {
@Id
@GeneratedValue
@Type(type = "uuid- char " )
private UUID id;
// getters, setters, etc. omitted
}
In Hibernate 6, the type attribute of the @Type annotation no longer exists. Initially, I tried just removing this annotation, but this caused an error because Hibernate then expects the primary key column type to be a UUID. In order to inform Hibernate that it should be stored as a varchar , I added the @JdbcType annotation
@Audited
@Entity
@Table(name = "foo" )
public class Foo {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
@JdbcType(VarcharJdbcType.class)
private UUID id;
// getters, setters, etc. omitted
}
While this fixes the mapping for the foo table, I now get a mapping error for the foo_aud.id column at startup.
>
>
>
> Caused by: org.hibernate.tool.schema.spi.SchemaManagementException:
> Schema-validation: *wrong column type encountered in column [id] in table
> [foo_aud] ; found varchar (Types#VARCHAR) ( #VARCHAR) ) , but expecting
> uuid (Types#UUID) ( #UUID) )*
> at
> org.hibernate.tool.schema.internal.AbstractSchemaValidator.validateColumnType(AbstractSchemaValidator.java:179)
> ~ [hibernate-core-6.1.5.Final.jar:6.1.5.Final]
>
>
*It seems that Hibernate/JPA is aware of the* @JdbcType annotation when computing the expected column type, but Envers is not.
Post-Migration Gradle Dependency Report
---------------------------------------
+--- org.springframework.data:spring-data-envers -> 3.0.0
| +--- org.springframework.data:spring-data-jpa:3.0.0 (*)
| +--- org.hibernate.orm:hibernate-envers:6.1.4.Final -> 6.1.5.Final
| | +--- org.hibernate.orm:hibernate-core:6.1.5.Final (*)
| | +--- org.jboss.logging:jboss-logging:3.4.3.Final -> 3.5.0.Final
| | +--- jakarta.xml.bind:jakarta.xml.bind-api:3.0.1 -> 4.0.0 (*)
| | +--- org.glassfish.jaxb:jaxb-runtime:3.0.2 -> 4.0.1 (*)
| | +--- org.hibernate.common:hibernate-commons-annotations:6.0.2.Final
( 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#100210- sha1:4037f92 )
1 year, 4 months