{"record":{"id":"e1c6516eac55b6b6","repo":"hibernate/hibernate-orm","slug":"not-a-treatable-type","errorCode":null,"errorMessage":"Not a treatable type: {}","messagePattern":"Not a treatable type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/domain/SqmListJoin.java","lineNumber":176,"sourceCode":"\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <S extends E> SqmTreatedListJoin<O,E,S> treatAs(@Nonnull EntityDomainType<S> treatTarget, @Nullable String alias) {\n\t\treturn treatAs( treatTarget, alias, false );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <S extends E> SqmTreatedListJoin<O, E, S> treatAs(@Nonnull Class<S> treatJavaType, @Nullable String alias, boolean fetch) {\n\t\tfinal var treatTarget = nodeBuilder().getDomainModel().managedType( treatJavaType );\n\t\tfinal var treat = (SqmTreatedListJoin<O, E, S>) findTreat( treatTarget, alias );\n\t\tif ( treat == null ) {\n\t\t\tif ( treatTarget instanceof TreatableDomainType<S> ) {\n\t\t\t\treturn addTreat( new SqmTreatedListJoin<>( this, (SqmTreatableDomainType<S>) treatTarget, alias, fetch ) );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IllegalArgumentException( \"Not a treatable type: \" + treatJavaType.getName() );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\treturn treat;\n\t\t}\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <S extends E> SqmTreatedListJoin<O,E,S> treatAs(@Nonnull EntityDomainType<S> treatTarget, @Nullable String alias, boolean fetch) {\n\t\tfinal var treat = (SqmTreatedListJoin<O, E, S>) findTreat( treatTarget, alias );\n\t\tif ( treat == null ) {\n\t\t\treturn addTreat( new SqmTreatedListJoin<>( this, (SqmEntityDomainType<S>) treatTarget, alias, fetch ) );\n\t\t}\n\t\telse {\n\t\t\treturn treat;\n\t\t}\n\t}","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/domain/SqmListJoin.java#L158-L194","documentation":"SqmListJoin.treatAs(Class) resolves the target Java class through the domain model and requires the result to be a TreatableDomainType. When the element/target is not treatable - typically an element collection of a non-polymorphic embeddable, or a target outside a mapped inheritance hierarchy - IllegalArgumentException is thrown naming the class. Only entity-typed list joins (or explicitly polymorphic embeddables in Hibernate 7) can be treated.","triggerScenarios":"Criteria listJoin.treatAs(WorkAddress.class) where the join is an @ElementCollection over an embeddable without @EmbeddedPolymorphism, or the target class is not a mapped treatable subtype of the element type; HQL 'join treat(o.items as Sub) i' over an element collection.","commonSituations":"Treating @ElementCollection joins like @OneToMany joins; Hibernate 7 embeddable treat support that requires polymorphism to be explicitly enabled; passing an entity class as treat target for an embeddable collection; passing a mapped-superclass or unmapped class.","solutions":["Confirm the joined attribute is a @OneToMany/@ManyToMany to an entity with an inheritance hierarchy, and the target is a mapped @Entity subclass of that element type","For embeddable elements that need treat, enable embeddable polymorphism (Hibernate 7 @EmbeddedPolymorphism on the embeddable supertype) so the resolved type becomes SqmTreatableDomainType","If the collection holds plain embeddables/basic values, remove the treatAs and filter on attributes instead","Remodel the collection as an entity association if subtype-specific queries are essential"],"exampleFix":"// before: addresses is @ElementCollection over @Embeddable Address (no polymorphism)\nListJoin<Person, Address> a = p.join(Person_.addresses);\na.treatAs(WorkAddress.class); // \"Not a treatable type: ...WorkAddress\"\n\n// after: enable embeddable polymorphism on the supertype\n// @EmbeddedPolymorphism @Embeddable abstract class Address { ... }\n// @Embeddable class WorkAddress extends Address { ... }\nListJoin<Person, Address> a2 = p.join(Person_.addresses);\na2.treatAs(WorkAddress.class); // resolves to SqmTreatableDomainType","handlingStrategy":"validation","validationCode":"// before treatAs on a list join, check the element type is an entity in a hierarchy\nListAttribute<?, ?> attr = (ListAttribute<?, ?>) join.getAttribute();\nif (attr.getElementType().getPersistenceType() != jakarta.persistence.metamodel.Type.PersistenceType.ENTITY) {\n    // element collections (basic/embeddable) cannot be treated to entity subtypes\n    throw new IllegalArgumentException(\n        \"Cannot TREAT join of non-entity elements: \" + attr.getName());\n}\nreturn join.treatAs(targetClass, null, false);","typeGuard":"static boolean treatableListJoin(SqmListJoin<?, ?> join) {\n    return join.getReferencedPathSource().getPathType() instanceof SqmEntityType<?>;\n}","tryCatchPattern":"try {\n    treated = listJoin.treatAs(targetClass, null, false);\n} catch (IllegalArgumentException | ClassCastException e) {\n    // target class is not a mapped treatable subtype: verify hierarchy/polymorphism config\n    throw new IllegalArgumentException(\"Not a treatable target for this join\", e);\n}","preventionTips":["Verify the joined attribute is an entity collection (@OneToMany) before treating","For embeddable collections, enable @EmbeddedPolymorphism (Hibernate 7) or remodel as entities","Treat targets must be mapped subtypes within the element type's hierarchy","Add a startup check that resolves all treat target classes against the metamodel"],"tags":["hibernate","criteria-api","treat","element-collection","list-join","sqm"],"backgroundTag":"invalid-treat-target","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}