Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring-data-envers 3.0.0 expects the wrong column type for audit table keys #2712

Closed
donalmurtagh opened this issue Nov 28, 2022 · 2 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@donalmurtagh
Copy link

donalmurtagh commented Nov 28, 2022

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)], but expecting [uuid (Types#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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 28, 2022
@donalmurtagh donalmurtagh changed the title spring-data-envers 3.0.0 expects the wrong type for audit table keys spring-data-envers 3.0.0 expects the wrong column type for audit table keys Nov 28, 2022
@schauder
Copy link
Contributor

This seems to be a Hibernate/Envers problem. I don't think there is much the Spring Data team can do about this.

@donalmurtagh
Copy link
Author

I've reported the issue to Hibernate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants