hibernate/hibernate-orm · error · IllegalArgumentException
Not a treatable type: {}
Error message
Not a treatable type: {} What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/domain/SqmListJoin.java:176
}
@Override
@Nonnull
public <S extends E> SqmTreatedListJoin<O,E,S> treatAs(@Nonnull EntityDomainType<S> treatTarget, @Nullable String alias) {
return treatAs( treatTarget, alias, false );
}
@Override
@Nonnull
public <S extends E> SqmTreatedListJoin<O, E, S> treatAs(@Nonnull Class<S> treatJavaType, @Nullable String alias, boolean fetch) {
final var treatTarget = nodeBuilder().getDomainModel().managedType( treatJavaType );
final var treat = (SqmTreatedListJoin<O, E, S>) findTreat( treatTarget, alias );
if ( treat == null ) {
if ( treatTarget instanceof TreatableDomainType<S> ) {
return addTreat( new SqmTreatedListJoin<>( this, (SqmTreatableDomainType<S>) treatTarget, alias, fetch ) );
}
else {
throw new IllegalArgumentException( "Not a treatable type: " + treatJavaType.getName() );
}
}
else {
return treat;
}
}
@Override
@Nonnull
public <S extends E> SqmTreatedListJoin<O,E,S> treatAs(@Nonnull EntityDomainType<S> treatTarget, @Nullable String alias, boolean fetch) {
final var treat = (SqmTreatedListJoin<O, E, S>) findTreat( treatTarget, alias );
if ( treat == null ) {
return addTreat( new SqmTreatedListJoin<>( this, (SqmEntityDomainType<S>) treatTarget, alias, fetch ) );
}
else {
return treat;
}
}View on GitHub (pinned to fad1729dce)
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
Example fix
// before: addresses is @ElementCollection over @Embeddable Address (no polymorphism)
ListJoin<Person, Address> a = p.join(Person_.addresses);
a.treatAs(WorkAddress.class); // "Not a treatable type: ...WorkAddress"
// after: enable embeddable polymorphism on the supertype
// @EmbeddedPolymorphism @Embeddable abstract class Address { ... }
// @Embeddable class WorkAddress extends Address { ... }
ListJoin<Person, Address> a2 = p.join(Person_.addresses);
a2.treatAs(WorkAddress.class); // resolves to SqmTreatableDomainType Defensive patterns
Strategy: validation
Validate before calling
// before treatAs on a list join, check the element type is an entity in a hierarchy
ListAttribute<?, ?> attr = (ListAttribute<?, ?>) join.getAttribute();
if (attr.getElementType().getPersistenceType() != jakarta.persistence.metamodel.Type.PersistenceType.ENTITY) {
// element collections (basic/embeddable) cannot be treated to entity subtypes
throw new IllegalArgumentException(
"Cannot TREAT join of non-entity elements: " + attr.getName());
}
return join.treatAs(targetClass, null, false); Type guard
static boolean treatableListJoin(SqmListJoin<?, ?> join) {
return join.getReferencedPathSource().getPathType() instanceof SqmEntityType<?>;
} Try / catch
try {
treated = listJoin.treatAs(targetClass, null, false);
} catch (IllegalArgumentException | ClassCastException e) {
// target class is not a mapped treatable subtype: verify hierarchy/polymorphism config
throw new IllegalArgumentException("Not a treatable target for this join", e);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Embeddable paths cannot be TREAT-ed to an entity type
- Cannot treat plural valued simple paths
- Cross join treats can not be aliased
- Cross join treats can not be fetched
- MappedSuperclassType cannot be used to create an SqmPath - t
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e1c6516eac55b6b6.
Report an issue: GitHub.