{"record":{"id":"fe48a78324b98245","repo":"hibernate/hibernate-orm","slug":"could-not-resolve-attribute-name-of-return","errorCode":null,"errorMessage":"Could not resolve attribute '${name}' of '${returnedClassName}' (must be one of '${names}')","messagePattern":"Could not resolve attribute '(.+?)' of '(.+?)' \\(must be one of '(.+?)'\\)","errorType":"exception","errorClass":"PropertyNotFoundException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/ComponentType.java","lineNumber":719,"sourceCode":"\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\t@Override\n\tpublic boolean isEmbedded() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic int getPropertyIndex(String name) {\n\t\tfinal var names = getPropertyNames();\n\t\tfor ( int i = 0, max = names.length; i < max; i++ ) {\n\t\t\tif ( names[i].equals( name ) ) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\t\tthrow new PropertyNotFoundException(\n\t\t\t\t\"Could not resolve attribute '\" + name + \"' of '\" + getReturnedClassName() + \"'\"\n\t\t\t\t\t+ \" (must be one of '\" + join(\"', '\", names) + \"')\"\n\t\t);\n\t}\n\n\tpublic int[] getOriginalPropertyOrder() {\n\t\treturn originalPropertyOrder;\n\t}\n\n\tprivate Boolean canDoExtraction;\n\n\t@Override\n\tpublic boolean canDoExtraction() {\n\t\tif ( canDoExtraction == null ) {\n\t\t\tcanDoExtraction = determineIfProcedureParamExtractionCanBePerformed();\n\t\t}\n\t\treturn canDoExtraction;\n\t}","sourceCodeStart":701,"sourceCodeEnd":737,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java#L701-L737","documentation":"ComponentType.getPropertyIndex (ComponentType.java:708-721) resolves an attribute name to its position inside an @Embedded/@Embeddable component by scanning the configured property names; an unknown name throws PropertyNotFoundException, and the message enumerates both the missing attribute and the complete list of legal attribute names for the component class.","triggerScenarios":"HQL/JPQL or Criteria paths that reference a wrong attribute on an embedded, e.g. 'from Person p where p.address.stret = :s' (typo for 'street'); programmatic getPropertyIndex(name) calls on ComponentType; queries generated from stale metamodels after an embeddable field was renamed or removed; @AttributeOverride scenarios where developers assume the overridden column name is also the attribute name.","commonSituations":"Typos in hand-written JPQL on embedded objects; renaming a field in the embeddable without updating queries; DTO/specification generators using old property lists; confusion between the column name (changed via @AttributeOverride/@Column) and the Java attribute name (which getPropertyIndex expects).","solutions":["Fix the attribute name in the query to one of the names listed in the message (they are the embeddable's Java field/property names).","If you renamed the embeddable field, update every JPQL/Criteria path that traverses it.","Remember @AttributeOverride/@Column change the column name, not the attribute name - keep using the Java name in queries.","If the path was meant to reach a related entity, re-check that the property is an association, not an embeddable."],"exampleFix":"// before\nList<Person> rs = session.createQuery(\n    \"from Person p where p.address.stret = :s\", Person.class) // typo\n    .setParameter(\"s\", \"Main St\").getResultList();\n\n// after\nList<Person> rs = session.createQuery(\n    \"from Person p where p.address.street = :s\", Person.class)\n    .setParameter(\"s\", \"Main St\").getResultList();","handlingStrategy":"validation","validationCode":"// Validate every embedded path against the metamodel before executing JPQL\nstatic void validateEmbeddablePath(Metamodel mm, Class<?> root,\n                                    String embeddableAttr, String field) {\n    Attribute<?, ?> a = mm.entity(root).getAttribute(embeddableAttr);\n    EmbeddableType<?> et = (EmbeddableType<?>) ((SingularAttribute<?, ?>) a).getType();\n    et.getAttribute(field); // throws IllegalArgumentException listing valid names early\n}","typeGuard":"static boolean hasAttribute(EmbeddableType<?> embeddable, String name) {\n    return embeddable.getAttributes().stream()\n        .anyMatch(a -> a.getName().equals(name));\n}","tryCatchPattern":"try {\n    return session.createQuery(jpql, Person.class).getResultList();\n} catch (IllegalArgumentException e) {\n    if (e.getCause() instanceof PropertyNotFoundException pnfe) {\n        throw new QueryValidationException(\"Unknown embeddable attribute in query: \"\n            + pnfe.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Write JPQL against the embeddable's Java field names, not overridden column names.","When renaming embeddable fields, search the codebase for 'entityName.field.' path prefixes.","Prefer Criteria API with static metamodel references so attribute renames become compile errors."],"tags":["hibernate","embedded","embeddable","hql","property-not-found","typo"],"backgroundTag":"property-not-found","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}