{"record":{"id":"5c5a344b2fe56cf9","repo":"hibernate/hibernate-orm","slug":"not-a-treatable-type-treatjavatype-getname-5c5a34","errorCode":null,"errorMessage":"Not a treatable type: ${treatJavaType.getName()}","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/SqmMapJoin.java","lineNumber":181,"sourceCode":"\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <S extends V> SqmTreatedMapJoin<L, K, V, S> treatAs(@Nonnull Class<S> treatJavaType, @Nullable String alias) {\n\t\treturn treatAs( treatJavaType, alias, false );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <S extends V> SqmTreatedMapJoin<L, K, V, 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 = (SqmTreatedMapJoin<L, K, V, S>) findTreat( treatTarget, alias );\n\t\tif ( treat == null ) {\n\t\t\tif ( treatTarget instanceof TreatableDomainType<S> ) {\n\t\t\t\treturn addTreat( new SqmTreatedMapJoin<>( 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@Nonnull\n\t@Override\n\tpublic <S extends V> SqmTreatedMapJoin<L, K, V, S> treatAs(@Nonnull EntityDomainType<S> treatTarget) {\n\t\treturn treatAs( treatTarget, null );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <S extends V> SqmTreatedMapJoin<L, K, V, S> treatAs(@Nonnull EntityDomainType<S> treatTarget, @Nullable String alias, boolean fetch) {\n\t\tfinal var treat = (SqmTreatedMapJoin<L, K, V, S>) findTreat( treatTarget, alias );\n\t\tif ( treat == null ) {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/domain/SqmMapJoin.java#L163-L199","documentation":"SqmMapJoin.treatAs(Class, alias, fetch) downcasts a map join's value type V to a subtype S. It resolves the class via nodeBuilder().getDomainModel().managedType(treatJavaType) and requires the result to implement TreatableDomainType (entities and embeddables do); anything else - typically a @MappedSuperclass - throws IllegalArgumentException 'Not a treatable type: <FQCN>'. The sibling overload treatAs(EntityDomainType, alias, fetch) skips this check entirely because the metamodel type is already trusted.","triggerScenarios":"Calling mapJoin.treatAs(SubType.class) or mapJoin(SubType.class) (HQL `join treat(x.map as Sub)` routes here too) where SubType resolves to a managed type that is not treatable - a @MappedSuperclass base class, or a class not mapped as @Entity/@Embeddable in this persistence unit.","commonSituations":"Treating a Map<String, Animal> join to Animal where Animal is a @MappedSuperclass rather than a mapped entity; wrong import using an identically named unmapped class; entity classes live in a module not included in the persistence unit; embeddable-valued maps treated against non-embeddable subtypes.","solutions":["Pass a concrete @Entity subtype of the map value type, e.g. mapJoin.treatAs(Cat.class)","Prefer the type-safe overload: mapJoin.treatAs( metamodel.entity( Cat.class ) ) - it bypasses the class-resolution check","Verify the treat target is annotated @Entity (not @MappedSuperclass) and is part of the same persistence unit","If the hierarchy root is a @MappedSuperclass, treat directly to each concrete subclass used in the query"],"exampleFix":"// before - Animal is a @MappedSuperclass -> 'Not a treatable type: ...Animal'\nSqmTreatedMapJoin<Person, String, Animal, Cat> tj = mapJoin.treatAs( Animal.class );\n\n// after - treat to the concrete @Entity subtype\nSqmTreatedMapJoin<Person, String, Animal, Cat> tj = mapJoin.treatAs( Cat.class );\n// or, skipping class resolution entirely:\nSqmTreatedMapJoin<Person, String, Animal, Cat> tj2 =\n        mapJoin.treatAs( metamodel.entity( Cat.class ) );","handlingStrategy":"validation","validationCode":"import org.hibernate.metamodel.model.domain.TreatableDomainType;\n\nManagedType<?> candidate;\ntry {\n    candidate = entityManager.getMetamodel().managedType( treatClass );\n} catch ( IllegalArgumentException e ) {\n    throw new IllegalArgumentException( \"Not a managed type: \" + treatClass.getName(), e );\n}\nif ( !(candidate instanceof TreatableDomainType<?>) ) {\n    throw new IllegalArgumentException(\n            \"Not a treatable type (use a concrete @Entity subtype): \" + treatClass.getName() );\n}\nreturn mapJoin.treatAs( treatClass );","typeGuard":"static boolean isTreatableTarget(jakarta.persistence.metamodel.Metamodel mm, Class<?> c) {\n    try {\n        return mm.managedType( c ) instanceof org.hibernate.metamodel.model.domain.TreatableDomainType<?>;\n    } catch ( IllegalArgumentException e ) {\n        return false; // not managed at all\n    }\n}","tryCatchPattern":"try {\n    join = mapJoin.treatAs( treatClass );\n} catch ( IllegalArgumentException e ) {\n    if ( e.getMessage() != null && e.getMessage().startsWith( \"Not a treatable type\" ) ) {\n        throw new IllegalArgumentException( \"Treat target \" + treatClass.getName()\n                + \" is not an @Entity/@Embeddable in this persistence unit\", e );\n    }\n    throw e;\n}","preventionTips":["Only treat to concrete @Entity subtypes of the map value type","Prefer treatAs(EntityDomainType) via metamodel.entity(Sub.class)","Never treat to a @MappedSuperclass-annotated class","Assert at startup that every treat target resolves to an entity in the persistence unit","Beware same-simple-name imports of unmapped classes"],"tags":["hibernate","criteria-api","treat-as","sqm","metamodel","inheritance","map-join"],"backgroundTag":"jpa-treat-as-non-treatable-type","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}