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 …