Starting with Hibernate 6 (reproducible with 6.0.0-6.1.7), schema validation fails during startup if an audited entity has a CLOB/NCLOB column. The schema validation complains about the type of the CLOB/NCLOB column in the audit table. Given the following entity:
@Entity
@Audited
class TestEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Lob
@Column(columnDefinition = "nclob")
private String nclobColumn;
}
and the following Liquibase change set:
<changeSet id="setup schema" author="me">
<createTable tableName="revinfo">
<column name="rev" type="int" autoIncrement="true">
<constraints primaryKey="true" primaryKeyName="pk_revinfo"/>
</column>
<column name="revtstmp" type="bigint">
<constraints nullable="false"/>
</column>
</createTable>
<createTable tableName="test_entity">
<column name="id" type="bigint" autoIncrement="true">
<constraints primaryKey="true" primaryKeyName="pk_test_entity"/>
</column>
<column name="nclob_column" type="nclob"/>
</createTable>
<createTable tableName="test_entity_aud">
<column name="id" type="bigint">
<constraints primaryKey="true" primaryKeyName="pk_test_entity_aud"/>
</column>
<column name="rev" type="int">
<constraints primaryKey="true"
primaryKeyName="pk_test_entity_aud"
referencedTableName="revinfo"
referencedColumnNames="rev"
foreignKeyName="fk_test_entity_aud_rev_revinfo_rev"/>
</column>
<column name="revtype" type="tinyint">
<constraints nullable="false"/>
</column>
<column name="nclob_column" type="nclob"/>
</createTable>
</changeSet>
And hibernate.hbm2ddl.auto=validate, schema validation fails with the following exception:
The exact same setup works on 5.6.15. In reproducers.zip I have attached two example projects. Both are identical Spring Boot projects, one with Spring Boot 2.7.9 and Hibernate 5, the other with Spring Boot 3.0.4 and Hibernate 6. Both projects use the same Liquibase (4.18.0) and H2 (2.1.214) versions. Extract them and run
The Hibernate 5 project starts and shuts down correctly, the Hibernate 6 project fails with the above mentioned schema validation error. The same error can be reproduced in Hibernate 5 by removing the @Lob annotation from the nclobColumn attribute. Maybe Hibernate/Envers 6 have issues with that annotation? Whether @Lob is present or not does not make a difference in Hibernate 6, the error is raised in both scenarios. |