A project consists of two Maven modules. One is API and holds some enum classes. The other is a Spring Boot application, currently 3.2.0. When upgrading it to Spring Boot 3.2.1, which pulls in Hibernate Core 6.4.1.Final instead of 6.3.1.Final all enum mappings break in @DataJpaTest with exceptions like:

ClassCast class de…Level cannot be cast to class [B (de…Level is in unnamed module of loader 'app'; [B is in module java.base of loader 'bootstrap')

Whereas the package omitted here is the same in both occurences. The enum itself is also referenced in JPA Queries by full qualified name which yields:

CustomImplTest.aggregate_empty:44 » SQLGrammar could not prepare statement [field "BEZUG"
not found
Column "BEZUG" not found; SQL statement:

Affected enum fields are annotated with:

@Column(nullable = false) // this varies
@JdbcTypeCode(SqlTypes.NAMED_ENUM)  // to have native PostgreSQLEnums as well as H2-compatibility with a custom H2 dialect to map this to VARCHAR
@Basic(optional = false)

Our custom H2 dialect does this:

public class MyH2Dialect extends H2Dialect {

    @Override
    protected void registerColumnTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
        super.registerColumnTypes(typeContributions, serviceRegistry);
        final DdlTypeRegistry ddlTypeRegistry = typeContributions.getTypeConfiguration().getDdlTypeRegistry();
        ddlTypeRegistry.addDescriptor(new DdlTypeImpl(SqlTypes.NAMED_ENUM, "varchar(255)", "varchar", this));
    }
}

Reverting Hibernate Core to 6.3.1.Final while keeping Spring Boot at 3.2.1 makes all issues disappear again. No code changes are necessary, only changes to of hibernate-core. Using Spring Boot 3.2.0 makes all tests run successfully.

In addition skipping tests and starting the application makes system tests accessing the application directly pass successfully. Even the Flyway migration of the application runs smoothly.

Project does not hold any module-info.java, uses JDK 17 and Maven 3.8 to build and runs on JDK 17.

Comment From: wilkinsona

Thanks for the report.

Reverting Hibernate Core to 6.3.1.Final while keeping Spring Boot at 3.2.1 makes all issues disappear again

Please try Hibernate 6.4.2. If that does not help, please report the problem to the Hibernate team. They unexpectedly ended support of 6.3.x so we felt that our least-bad option was to upgrade to 6.4.x. Unfortunately, given the results of your investigation, it would appear that 6.4.1 contains a regression but we don't want to drop back to 6.3.x as it's a dead-end from a support perspective.

Comment From: onkobu

Thanks for the fast reply. I am uncertain whether this is a Hibernate issue. As stated before the application itself runs perfectly fine. Entities with the mentioned enums can be persisted and queried. Only @DataJpaTest in combination with H2 causes the exceptions. With Hibernate 6.4.2.Final all issues persist.

From Spring Boot's point of view it is simple delegation to ORM provider? Will forward the issue and backlink.

Comment From: onkobu

https://hibernate.atlassian.net/browse/HHH-17657

Comment From: onkobu

Found a solution providing a JdbcType derived from Postgres-variant. See comments of the Hibernate-issue for code samples.