{"record":{"id":"23c0cbf76eeb03c7","repo":"hibernate/hibernate-orm","slug":"no-node-for-attribute","errorCode":null,"errorMessage":"No node for attribute: {}","messagePattern":"No node for attribute: (.+?)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/graph/internal/GraphImpl.java","lineNumber":116,"sourceCode":"\t\t\t&& attributeNodes.containsKey( attribute );\n\t}\n\n\t@Override\n\tpublic boolean hasAttributeNode(@Nonnull Attribute<? super J, ?> attribute) {\n\t\treturn attributeNodes != null\n\t\t\t&& attributeNodes.containsKey( (PersistentAttribute<? super J, ?>) attribute );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <Y> AttributeNodeImplementor<Y,?,?> getAttributeNode(@Nonnull String attributeName) {\n\t\tfinal var attribute = findAttributeInSupertypes( attributeName );\n\t\tif ( attribute == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Unknown attribute: \" + attributeName );\n\t\t}\n\t\tfinal var node = attributeNodes == null ? null : attributeNodes.get( attribute );\n\t\tif ( node == null ) {\n\t\t\tthrow new NoSuchElementException( \"No node for attribute: \" + attributeName );\n\t\t}\n\t\t@SuppressWarnings(\"unchecked\") // The JPA API is unsafe by nature\n\t\tfinal var castNode = (AttributeNodeImplementor<Y, ?, ?>) node;\n\t\treturn castNode;\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <Y> AttributeNodeImplementor<Y,?,?> getAttributeNode(@Nonnull Attribute<? super J, Y> attribute) {\n\t\tfinal var node = attributeNodes == null ? null\n\t\t\t\t: attributeNodes.get( (PersistentAttribute<? super J, ?>) attribute );\n\t\tif ( node == null ) {\n\t\t\tthrow new NoSuchElementException( \"No node for attribute: \" + attribute );\n\t\t}\n\t\t@SuppressWarnings(\"unchecked\")\n\t\tfinal var castNode = (AttributeNodeImplementor<Y, ?, ?>) node;\n\t\treturn castNode;\n\t}","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/graph/internal/GraphImpl.java#L98-L134","documentation":"GraphImpl.getAttributeNode(String) throws NoSuchElementException('No node for attribute: ...') when the name resolves to a real attribute of the graphed type (including inherited ones) but this graph holds no node for it — nothing was ever added via addAttributeNode, or the node was removed. It signals an absent node, not an unknown attribute (that case throws IllegalArgumentException).","triggerScenarios":"Calling getAttributeNode(name) on a freshly created empty graph (nodes only exist after addAttributeNode), after the node was removed, or when inspecting a graph parsed from a string or loaded by name that never mentioned the attribute.","commonSituations":"Graph merge/inspection utilities assuming nodes exist for all attributes; reading named/parsed graphs for attributes that were never included; interleaving removal and lookup logic.","solutions":["Create the node instead of assuming it exists: addAttributeNode(name) returns the existing or newly created node","Check presence via getAttributeNodes() names (or hasAttributeNode after validating the name) before fetching","When inspecting graphs you did not build, treat a missing node as 'attribute not fetched' rather than an error"],"exampleFix":"// before\nvar node = graph.getAttributeNode(\"customer\"); // graph never added it → NoSuchElementException\n\n// after — addAttributeNode returns the existing or newly created node\nvar node = graph.addAttributeNode(\"customer\");","handlingStrategy":"validation","validationCode":"// Check node presence without exceptions before getAttributeNode(name)\nstatic Optional<jakarta.persistence.AttributeNode<?>> nodeFor(EntityGraph<?> graph, String attrName) {\n    return graph.getAttributeNodes().stream()\n            .filter(n -> n.getAttributeName().equals(attrName))\n            .findFirst();\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create nodes with addAttributeNode(name) instead of assuming they exist","Inspect getAttributeNodes() when reading graphs you did not build","Remember the split: IllegalArgumentException = bad attribute name; NoSuchElementException = valid name without a node"],"tags":["hibernate","entity-graph","attribute-node","nosuchelementexception","jpa"],"backgroundTag":"entity-graph-missing-node","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}