{"record":{"id":"dbc363c749852c38","repo":"hibernate/hibernate-orm","slug":"argument-of-naturalid-is-a-and-has-a","errorCode":null,"errorMessage":"Argument '{}' of 'naturalid()' is a '{}' and has a composite natural id","messagePattern":"Argument '(.+?)' of 'naturalid\\(\\)' is a '(.+?)' and has a composite natural id","errorType":"exception","errorClass":"FunctionArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":3598,"sourceCode":"\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\" );\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();","sourceCodeStart":3580,"sourceCodeEnd":3616,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L3580-L3616","documentation":"Error \"Argument '{}' of 'naturalid()' is a '{}' and has a composite natural id\" thrown in hibernate/hibernate-orm.","triggerScenarios":"The naturalid() function is misused: Argument '<value>' of 'naturalid()' is a '<value>' and has a composite natural id","commonSituations":"Calling naturalid() on entities without a @NaturalId, with a composite natural id, or continuing a path from it.","solutions":["naturalid() does not support composite natural ids. Reference the individual natural-id attributes explicitly in the query instead of using naturalid() on an entity with a composite natural id."],"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"}