hibernate/hibernate-orm · error · FunctionArgumentException
Argument ' ' of 'naturalid()' does not resolve to an entity…
Error message
Argument '{}' of 'naturalid()' does not resolve to an entity type What it means
Thrown by SemanticQueryBuilder.handleNaturalIdPath when the argument of 'naturalid()' does not resolve to an entity type. 'naturalid()' is only meaningful for entities; the offending input is the argument path, which resolved to some non-identifiable domain type and is named in the exception.
Solutions
- The argument of naturalid() must resolve to an entity type. Verify the path or alias passed to naturalid() refers to a mapped entity and is spelled correctly in the HQL.
Defensive patterns
Strategy: validation
When it happens
Trigger: A name/path expected to denote an entity type does not: Argument '<value>' of 'naturalid()' does not resolve to an entity type
Common situations: Passing non-entity arguments to version()/naturalid(), or a TREAT target / entity name that is not a mapped entity; commonly a typo or unmapped class.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/3ad6bc102327c771.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:3609
if ( attributes == null ) {
throw new FunctionArgumentException( "Argument '" + sqmPath.getNavigablePath()
+ "' of 'naturalid()' is a '" + identifiableType.getTypeName()
+ "' and does not have a natural id"
);
}
else if ( attributes.size() > 1 ) {
throw new FunctionArgumentException( "Argument '" + sqmPath.getNavigablePath()
+ "' of 'naturalid()' is a '" + identifiableType.getTypeName()
+ "' and has a composite natural id"
);
}
final var naturalIdAttribute =
(SingularPersistentAttribute<? super U, ?>)
attributes.get( 0 );
return sqmPath.get( naturalIdAttribute );
}
throw new FunctionArgumentException( "Argument '" + sqmPath.getNavigablePath()
+ "' of 'naturalid()' does not resolve to an entity type" );
}
@Override
public SqmFkExpression<?> visitToOneFkReference(HqlParser.ToOneFkReferenceContext ctx) {
final var sqmPath = consumeDomainPath( (HqlParser.PathContext) ctx.getChild( 2 ) );
final var toOneReference = sqmPath.getResolvedModel();
final boolean validToOneRef =
toOneReference.getBindableType() == Bindable.BindableType.SINGULAR_ATTRIBUTE
&& toOneReference.getPathType() instanceof SqmEntityDomainType<?>;
if ( !validToOneRef ) {
throw new FunctionArgumentException(
String.format(
Locale.ROOT,
"Argument '%s' of 'fk()' function is not a single-valued association",
sqmPath.getNavigablePath()
)
);View on GitHub (pinned to fad1729dce)