{"record":{"id":"3ad6bc102327c771","repo":"hibernate/hibernate-orm","slug":"argument-of-naturalid-does-not-resolve-to","errorCode":null,"errorMessage":"Argument '{}' of 'naturalid()' does not resolve to an entity type","messagePattern":"Argument '(.+?)' of 'naturalid\\(\\)' does not resolve to an entity type","errorType":"exception","errorClass":"FunctionArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":3609,"sourceCode":"\t\t\tif ( attributes == null ) {\n\t\t\t\tthrow new FunctionArgumentException( \"Argument '\" + sqmPath.getNavigablePath()\n\t\t\t\t\t\t\t+ \"' of 'naturalid()' is a '\" + identifiableType.getTypeName()\n\t\t\t\t\t\t\t+ \"' and does not have a natural id\"\n\t\t\t\t);\n\t\t\t}\n\t\t\telse if ( attributes.size() > 1 ) {\n\t\t\t\tthrow new FunctionArgumentException( \"Argument '\" + sqmPath.getNavigablePath()\n\t\t\t\t\t\t\t+ \"' of 'naturalid()' is a '\" + identifiableType.getTypeName()\n\t\t\t\t\t\t\t+ \"' and has a composite natural id\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tfinal var naturalIdAttribute =\n\t\t\t\t\t(SingularPersistentAttribute<? super U, ?>)\n\t\t\t\t\t\t\tattributes.get( 0 );\n\t\t\treturn sqmPath.get( naturalIdAttribute );\n\t\t}\n\t\tthrow new FunctionArgumentException( \"Argument '\" + sqmPath.getNavigablePath()\n\t\t\t\t+ \"' of 'naturalid()' does not resolve to an entity type\" );\n\t}\n\n\t@Override\n\tpublic SqmFkExpression<?> visitToOneFkReference(HqlParser.ToOneFkReferenceContext ctx) {\n\t\tfinal var sqmPath = consumeDomainPath( (HqlParser.PathContext) ctx.getChild( 2 ) );\n\t\tfinal var toOneReference = sqmPath.getResolvedModel();\n\t\tfinal boolean validToOneRef =\n\t\t\t\ttoOneReference.getBindableType() == Bindable.BindableType.SINGULAR_ATTRIBUTE\n\t\t\t\t\t\t&& toOneReference.getPathType() instanceof SqmEntityDomainType<?>;\n\t\tif ( !validToOneRef ) {\n\t\t\tthrow new FunctionArgumentException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\"Argument '%s' of 'fk()' function is not a single-valued association\",\n\t\t\t\t\t\t\tsqmPath.getNavigablePath()\n\t\t\t\t\t)\n\t\t\t);","sourceCodeStart":3591,"sourceCodeEnd":3627,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L3591-L3627","documentation":"Error \"Argument '{}' of 'naturalid()' does not resolve to an entity type\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A name/path expected to denote an entity type does not: Argument '<value>' of 'naturalid()' does not resolve to an entity type","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}