Collection UserTypes cause a cast exception in 6.4

This exception occurred when trying to migrate hypersistence-utils to Hibernate 6.4. It looks like a collection user type, such as hypersistence-utils/hypersistence-utils-hibernate-63/src/main/java/io/hypersistence/utils/hibernate/type/array/IntArrayType.java at master · vladmihalcea/hypersistence-utils · GitHub can no longer be registered since it resolves to a CustomType which cannot be cast to BasicPluralType.

Opened a Jira issue: [HHH-17588] - Hibernate JIRA

It’s not clear to me what the fix should be, would love to contribute, but need a bit of guidance first.

2 Likes

Hi and thanks for reporting this problem. If you want to contribute, please start by creating a reproducer with our test case template (hibernate-test-case-templates/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java at main · hibernate/hibernate-test-case-templates · GitHub) and attach that to the Jira issue. Also, please post the full stack trace.

@beikov I added a test case to the issue. I tried it with 6.4.2, and the issue was replicated.

The problem is we can no longer define a custom Type that’s mapped to an ARRAY column type.

This is the error we are getting:

Caused by: java.lang.ClassCastException: class org.hibernate.type.CustomType cannot be cast to class org.hibernate.type.BasicPluralType (org.hibernate.type.CustomType and org.hibernate.type.BasicPluralType are in unnamed module of loader 'app')
	at org.hibernate.type.descriptor.sql.internal.ArrayDdlTypeImpl.getCastTypeName(ArrayDdlTypeImpl.java:34)
	at org.hibernate.sql.ast.spi.AbstractSqlAstTranslator.getCastTypeName(AbstractSqlAstTranslator.java:6353)
	at org.hibernate.sql.ast.spi.AbstractSqlAstTranslator.visitCastTarget(AbstractSqlAstTranslator.java:6300)
	at org.hibernate.sql.ast.tree.expression.CastTarget.accept(CastTarget.java:75)
	at org.hibernate.sql.ast.spi.AbstractSqlAstTranslator.render(AbstractSqlAstTranslator.java:6434)
	at org.hibernate.query.sqm.produce.function.internal.PatternRenderer.render(PatternRenderer.java:224)
	at org.hibernate.query.sqm.produce.function.internal.PatternRenderer.render(PatternRenderer.java:159)
	at org.hibernate.query.sqm.produce.function.internal.PatternRenderer.render(PatternRenderer.java:142)
	at org.hibernate.dialect.function.CastFunction.render(CastFunction.java:76)
	at org.hibernate.sql.ast.spi.AbstractSqlAstTranslator.renderCasted(AbstractSqlAstTranslator.java:5259)
	at org.hibernate.dialect.SqlAstTranslatorWithMerge.renderMergeUsingQuerySelection(SqlAstTranslatorWithMerge.java:156)
	at org.hibernate.dialect.SqlAstTranslatorWithMerge.renderMergeUsingQuery(SqlAstTranslatorWithMerge.java:145)
	at org.hibernate.dialect.SqlAstTranslatorWithMerge.renderMergeUsing(SqlAstTranslatorWithMerge.java:121)
	at org.hibernate.dialect.SqlAstTranslatorWithMerge.renderMergeStatement(SqlAstTranslatorWithMerge.java:77)
	at org.hibernate.dialect.SqlAstTranslatorWithMerge.createMergeOperation(SqlAstTranslatorWithMerge.java:43)
	at org.hibernate.dialect.H2Dialect.usingMerge(H2Dialect.java:912)
	at org.hibernate.dialect.H2Dialect.createOptionalTableUpdateOperation(H2Dialect.java:904)
	at org.hibernate.sql.model.internal.OptionalTableUpdate.createMutationOperation(OptionalTableUpdate.java:136)
	at org.hibernate.persister.entity.mutation.AbstractMutationCoordinator.createOperationGroup(AbstractMutationCoordinator.java:87)
	at org.hibernate.persister.entity.mutation.UpdateCoordinatorStandard.buildStaticUpdateGroup(UpdateCoordinatorStandard.java:1646)
	at org.hibernate.persister.entity.mutation.UpdateCoordinatorStandard.<init>(UpdateCoordinatorStandard.java:90)
	at org.hibernate.persister.entity.mutation.MergeCoordinator.<init>(MergeCoordinator.java:23)
	at org.hibernate.persister.entity.AbstractEntityPersister.buildMergeCoordinator(AbstractEntityPersister.java:3647)
	at org.hibernate.persister.entity.AbstractEntityPersister.doLateInit(AbstractEntityPersister.java:3415)
	at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:3679)
	at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:201)
	at org.hibernate.internal.SessionFactoryImpl.initializeMappingModel(SessionFactoryImpl.java:364)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:293)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:450)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:941)
	at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:127)
	at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:112)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:201)
2 Likes