How to fix BasicTypeImpl cannot cast to BasicPluralType, Can debug?

Hello,
As a new Hibernate, after days struggling, I fixed some errors in mapping and annotations. It is a very old applications, an entity contains multiple other entities, sometimes hard to identify a entity. The following exception says :

class org.hibernate.type.internal.BasicTypeImpl cannot be cast to class org.hibernate.type.BasicPluralType

Error occurred without execute a good SQL. I think it relates to entity settings, too vague. but show me the path. I tried to debug in vain.
Could somebody teach me, when Debug, is it possible to step into a function, Watch a Expressions, we can get the entity name?

Initial SessionFactory creation failed.java.lang.ClassCastException: class org.hibernate.type.internal.BasicTypeImpl cannot be cast to class org.hibernate.type.BasicPluralType (org.hibernate.type.internal.BasicTypeImpl and org.hibernate.type.BasicPluralType are in unnamed module of loader 'app')
java.lang.ClassCastException: class org.hibernate.type.internal.BasicTypeImpl cannot be cast to class org.hibernate.type.BasicPluralType (org.hibernate.type.internal.BasicTypeImpl 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:6992)
	at org.hibernate.sql.ast.spi.AbstractSqlAstTranslator.visitCastTarget(AbstractSqlAstTranslator.java:6939)
	at org.hibernate.sql.ast.tree.expression.CastTarget.accept(CastTarget.java:80)
	at org.hibernate.sql.ast.spi.AbstractSqlAstTranslator.render(AbstractSqlAstTranslator.java:7073)
	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:5813)
	at org.hibernate.dialect.OracleSqlAstTranslator.renderMergeSource(OracleSqlAstTranslator.java:695)
	at org.hibernate.dialect.SqlAstTranslatorWithUpsert.renderMergeUsing(SqlAstTranslatorWithUpsert.java:92)
	at org.hibernate.dialect.SqlAstTranslatorWithUpsert.renderUpsertStatement(SqlAstTranslatorWithUpsert.java:66)
	at org.hibernate.dialect.SqlAstTranslatorWithUpsert.createMergeOperation(SqlAstTranslatorWithUpsert.java:36)
	at org.hibernate.dialect.OracleDialect.createOptionalTableUpdateOperation(OracleDialect.java:1588)
	at org.hibernate.sql.model.internal.OptionalTableUpdate.createMutationOperation(OptionalTableUpdate.java:144)
	at org.hibernate.persister.entity.mutation.AbstractMutationCoordinator.createOperationGroup(AbstractMutationCoordinator.java:87)
	at org.hibernate.persister.entity.mutation.UpdateCoordinatorStandard.buildStaticUpdateGroup(UpdateCoordinatorStandard.java:1663)
	at org.hibernate.persister.entity.mutation.UpdateCoordinatorStandard.<init>(UpdateCoordinatorStandard.java:93)
	at org.hibernate.persister.entity.mutation.MergeCoordinator.<init>(MergeCoordinator.java:23)
	at org.hibernate.persister.entity.AbstractEntityPersister.buildMergeCoordinator(AbstractEntityPersister.java:3658)
	at org.hibernate.persister.entity.AbstractEntityPersister.doLateInit(AbstractEntityPersister.java:3404)
	at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:3690)
	at org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:202)
	at org.hibernate.internal.SessionFactoryImpl.initializeMappingModel(SessionFactoryImpl.java:371)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:300)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:457)
	at com.eng.maris.utility.HibernateUtil.getSessionFactory(HibernateUtil.java:29)
	at com.eng.maris.dao.AbstractDAO.<init>(AbstractDAO.java:79)

Thanks,
Eric

Hello, you could set a break point in OracleSqlAstTranslator#renderMergeSource to see which path is causing this error to be thrown when Hibernate tries to render a casted expression.

What version of Hibernate are you using? From the line numbers in the stack trace, it does not look like you’re on the latest version. Please consider upgrading to the latest stable version to see if the issue persists.

1 Like

Hi mbladel,
Thank you for the reply. The error I posted is with Hibernate 6.5.2. I just changed it to 6.4.9 and delete /repository from C:\Users\ezuo.m2, to force maven to reload libs. then I got the same error . 6.4.9 was the latest stable version when I first started hibernate in June. I changes so fast.
Following your instruction, I am going to debug.
Thanks,
Eric

Hi mbladel,
As you pointed, I find the problem and did a fix. it resolved.
Thanks,
Eric

Can someone tell me what was the solution? I am facing same issue. We are using spring-boot 3.3.0 and hibernate-6.5.2 which is part of spring boot. If you post what was the fix you did that would be really grateful

@ezuo Can you please share your solution?