{"record":{"id":"eb5173be904d6941","repo":"hibernate/hibernate-orm","slug":"argument-of-naturalid-is-a-and-does","errorCode":null,"errorMessage":"Argument '{}' of 'naturalid()' is a '{}' and does not have a natural id","messagePattern":"Argument '(.+?)' of 'naturalid\\(\\)' is a '(.+?)' and does not have a natural id","errorType":"exception","errorClass":"FunctionArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":3592,"sourceCode":"\t@Override\n\tpublic SqmPath<?> visitEntityNaturalIdExpression(HqlParser.EntityNaturalIdExpressionContext ctx) {\n\t\treturn visitEntityNaturalIdReference( ctx.entityNaturalIdReference() );\n\t}\n\n\t@Override\n\tpublic SqmPath<?> visitEntityNaturalIdReference(HqlParser.EntityNaturalIdReferenceContext ctx) {\n\t\tif ( ctx.pathContinuation() != null ) {\n\t\t\tthrow new UnsupportedOperationException( \"Path continuation from 'naturalid()' reference not yet implemented\" );\n\t\t}\n\t\treturn handleNaturalIdPath( consumeDomainPath( ctx.path() ) );\n\t}\n\n\tprivate static <U> SqmPath<?> handleNaturalIdPath(SqmPath<U> sqmPath) {\n\t\tif ( sqmPath.getReferencedPathSource().getPathType()\n\t\t\t\tinstanceof AbstractIdentifiableType<U> identifiableType ) {\n\t\t\tfinal var attributes = identifiableType.findNaturalIdAttributes();\n\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\" );","sourceCodeStart":3574,"sourceCodeEnd":3610,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L3574-L3610","documentation":"Error \"Argument '{}' of 'naturalid()' is a '{}' and does not have a natural id\" thrown in hibernate/hibernate-orm.","triggerScenarios":"The naturalid() function is misused: Argument '<value>' of 'naturalid()' is a '<value>' and does not have a natural id","commonSituations":"Calling naturalid() on entities without a @NaturalId, with a composite natural id, or continuing a path from it.","solutions":["The argument passed to naturalid() resolves to a type that declares no @NaturalId. Add a @NaturalId attribute to the entity, or call naturalid() on an entity that actually has one."],"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"}