hibernate/hibernate-orm · error · PathException

Could not resolve attribute '%s' of '%s' due to the attribut

Error message

Could not resolve attribute '%s' of '%s' due to the attribute being declared in multiple subtypes '%s' and '%s'

What it means

Thrown by AbstractEntityPersister.findSubPartInSubclassMappings while Hibernate resolves an attribute path (HQL, Criteria, or SQM navigation) against a polymorphic entity type. The lookup walks every subclass mapping type, and when two sibling subclasses each declare an attribute with the same name whose ModelParts are not compatible (different types or mappings), Hibernate cannot pick one unambiguously and throws a PathException naming both declaring classes. Attributes mapped once on a common root are found via declaredGenericAttributeMappings and never hit this conflict.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java:6540

				}
			}
			return null;
		}
	}

	private ModelPart findSubPartInSubclassMappings(String name) {
		final var declaredGenericAttribute = declaredGenericAttributeMappings.get( name );
		if ( declaredGenericAttribute != null ) {
			return declaredGenericAttribute;
		}

		ModelPart attribute = null;
		if ( isNotEmpty( subclassMappingTypes ) ) {
			for ( var subMappingType : subclassMappingTypes.values() ) {
				final var subDefinedAttribute = subMappingType.findSubTypesSubPart( name, null );
				if ( subDefinedAttribute != null ) {
					if ( attribute != null && !isCompatibleModelPart( attribute, subDefinedAttribute ) ) {
						throw new PathException( String.format(
								Locale.ROOT,
								"Could not resolve attribute '%s' of '%s' due to the attribute being declared in multiple subtypes '%s' and '%s'",
								name,
								getJavaType().getTypeName(),
								attribute.asAttributeMapping().getDeclaringType().getJavaType().getTypeName(),
								subDefinedAttribute.asAttributeMapping().getDeclaringType().getJavaType().getTypeName()
						) );
					}
					attribute = subDefinedAttribute;
				}
			}
		}
		return attribute;
	}

	@Override
	public ModelPart findSubTypesSubPart(String name, EntityMappingType treatTargetType) {
		final var declaredAttribute = declaredAttributeMappings.get( name );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Move the shared attribute onto the common superclass (or a @MappedSuperclass) so it is mapped exactly once
  2. If the two attributes genuinely differ, rename one of them and update all queries
  3. Query the concrete subclass that owns the attribute instead of the polymorphic root
  4. If both must keep the name, make their mappings identical so isCompatibleModelPart() accepts the pair

Example fix

// before
@Entity @Inheritance(strategy = JOINED)
class Person { }
class Author  extends Person { String alias; } // 'alias' declared here ...
class Editor extends Person { Integer alias; } // ... and here, incompatible type
// 'from Person p where p.alias = :a' -> PathException

// after
@Entity @Inheritance(strategy = JOINED)
class Person { String alias; } // declared once on the root
class Author  extends Person { }
class Editor extends Person { }
Defensive patterns

Strategy: try-catch

Validate before calling

Metamodel mm = sessionFactory.getMetamodel();
EntityType<?> root = mm.entity(Person.class);
int declared = 0;
for ( ManagedType<?> sub : mm.getSubtypes(root) ) {
    try {
        sub.getDeclaredAttribute("alias");
        declared++;
    }
    catch ( IllegalArgumentException notDeclaredHere ) { }
}
if ( declared > 1 ) {
    // 'alias' is ambiguous across siblings: do not use it from the polymorphic root
}

Try / catch

try {
    return session.createQuery("select p from Person p where p.alias = :a", Person.class)
                  .setParameter("a", a)
                  .list();
}
catch ( org.hibernate.query.PathException e ) { // extends SemanticException; thrown at query creation
    throw new IllegalArgumentException(
        "Attribute not uniquely resolvable across Person subtypes: " + e.getMessage(), e );
}

Prevention

When it happens

Trigger: Resolving a path like 'from Person p where p.alias = :x' on an inheritance root when 'alias' is declared separately (not inherited) in two subclasses with incompatible mappings; SQM findSubPart()/findSubTypesSubPart() calls during query translation, entity graphs, or Criteria attributes over a JOINED or union hierarchy with duplicated field names of different types.

Common situations: Copying a field into two sibling subclasses during refactoring; same-named columns with different types across union/implicit-polymorphism hierarchies; moving a field down from the superclass but leaving one subclass redeclaring it; dynamic-model or generic query builders hitting the root persister.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/3e30e2ea1fd0bbf9. Report an issue: GitHub.