@Any mapping not working on hql inserts

Hello,

Migrating from 5.6.4 to 6.2.6 I encountered a problem on HQL insert queries for entities using @Any mapping

On 5.6.4 the entity was mapped as follows:

@Entity
class DocumentVO {

@AnyMetaDef(name = “ReferenceTableDefinition”, metaType = “string”, idType = “long”, metaValues = {
@MetaValue(value = “DOCUMENT”, targetEntity = DocumentVO.class),
@MetaValue(value = “DOCCLIENT”, targetEntity = DocClientVO.class)
})
@Any(metaDef = “ReferenceTableDefinition”, metaColumn = @Column(name = “PARENTTABLE”), fetch = FetchType.LAZY)
@JoinColumn(name = “PARENTID”)
private IDocumentEntity parent;

}

On 6.2.6 the mapping was changed as follows:

@Entity
class DocumentVO {

@Any(fetch = FetchType.LAZY)
@JoinColumn(name = “PARENTID”)
@Column(name = “PARENTTABLE”)
@AnyKeyJavaType(value = LongJavaType.class)
@AnyDiscriminatorValue(discriminator = “DOCUMENT”, entity = DocumentVO.class)
@AnyDiscriminatorValue(discriminator = “DOCCLIENT”, entity = DocClientVO.class)
private IDocumentEntity parent;

}

Works fine if I load or persist new objects, but if I use HQL insert query, I have the following exception:

Caused by: java.lang.ClassCastException: class org.hibernate.query.sqm.sql.internal.DiscriminatedAssociationPathInterpretation cannot be cast to class org.hibernate.sql.ast.tree.update.Assignable (org.hibernate.query.sqm.sql.internal.DiscriminatedAssociationPathInterpretation and org.hibernate.sql.ast.tree.update.Assignable are in unnamed module of loader 'deployment.ngp.war' @32f999f9)
	at deployment.ngp.war//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitInsertionTargetPaths(BaseSqmToSqlAstConverter.java:1356)
	at deployment.ngp.war//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitInsertSelectStatement(BaseSqmToSqlAstConverter.java:1191)
	at deployment.ngp.war//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitInsertSelectStatement(BaseSqmToSqlAstConverter.java:434)
	at deployment.ngp.war//org.hibernate.query.sqm.tree.insert.SqmInsertSelectStatement.accept(SqmInsertSelectStatement.java:95)
	at deployment.ngp.war//org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.translate(BaseSqmToSqlAstConverter.java:775)
	at deployment.ngp.war//org.hibernate.query.sqm.internal.SimpleInsertQueryPlan.createInsertTranslator(SimpleInsertQueryPlan.java:68)
	at deployment.ngp.war//org.hibernate.query.sqm.internal.SimpleInsertQueryPlan.executeUpdate(SimpleInsertQueryPlan.java:93)
	at deployment.ngp.war//org.hibernate.query.sqm.internal.QuerySqmImpl.doExecuteUpdate(QuerySqmImpl.java:735)
	at deployment.ngp.war//org.hibernate.query.sqm.internal.QuerySqmImpl.executeUpdate(QuerySqmImpl.java:705)

HQL insert query sample:
insert into DocumentVO(parent, …) select d.parent, … from DocumentVO d where …

Have you tried using Hibernate 6.2.8 and 6.3.0? If this problems persist in the latest versions, this is probably a bug. Please create an issue in the issue tracker with a test case that reproduces the issue.

The problem occurs on 6.2.8 and 6.3.1-snapshot also.
Could not test using 6.3.0 since I encounter the same error reported in

[HHH-17208] - Hibernate JIRA was created

1 Like