{"record":{"id":"f1ab70adce8d1e60","repo":"hibernate/hibernate-orm","slug":"injection-of-parent-instance-into-embeddable-resul","errorCode":null,"errorMessage":"Injection of parent instance into embeddable result is not possible","messagePattern":"Injection of parent instance into embeddable result is not possible","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableInitializerImpl.java","lineNumber":562,"sourceCode":"\t\t\t\tassert setter != null;\n\t\t\t\tsetter.set( data.getInstance(), parent );\n\t\t\t}\n\t\t}\n\t\t// else embeddable defined no parent injection\n\t}\n\n\tprivate Initializer<?> determineOwningInitializer() {\n\t\t// Try to find the first non-embeddable fetch parent access\n\t\t// todo (6.x) - allow injection of containing composite as parent if\n\t\t//  \tit is the direct parent\n\t\tInitializerParent<?> parent = this.parent;\n\t\twhile ( parent != null ) {\n\t\t\tif ( !parent.isEmbeddableInitializer() ) {\n\t\t\t\treturn parent;\n\t\t\t}\n\t\t\tparent = parent.getParent();\n\t\t}\n\t\tthrow new UnsupportedOperationException( \"Injection of parent instance into embeddable result is not possible\" );\n\t}\n\n\tprivate Object determineParentInstance(Initializer<?> parentInitializer, RowProcessingState rowProcessingState) {\n\t\tif ( parentInitializer == null ) {\n\t\t\tthrow new UnsupportedOperationException( \"Cannot determine Embeddable: \" + navigablePath + \" parent instance, parent initializer is null\" );\n\t\t}\n\n\t\tfinal var collectionInitializer = parentInitializer.asCollectionInitializer();\n\t\tif ( collectionInitializer != null ) {\n\t\t\treturn collectionInitializer.getCollectionInstance( rowProcessingState ).getOwner();\n\t\t}\n\n\t\tfinal var parentEntityInitializer = parentInitializer.asEntityInitializer();\n\t\tif ( parentEntityInitializer != null ) {\n\t\t\treturn parentEntityInitializer.getTargetInstance( rowProcessingState );\n\t\t}\n\n\t\tthrow new UnsupportedOperationException( \"The Embeddable: \" + navigablePath + \" parent initializer is neither an instance of an EntityInitializer nor of a CollectionInitializer\" );","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableInitializerImpl.java#L544-L580","documentation":"When Hibernate needs a parent instance for an embeddable it is building (e.g. to inject via @Parent or to resolve the owning row), EmbeddableInitializerImpl.determineOwningInitializer() walks the initializer chain looking for the first parent that is NOT an embeddable initializer (i.e. an entity or collection initializer). If the whole chain consists of embeddable initializers, there is no owner to inject from, and it throws UnsupportedOperationException('Injection of parent instance into embeddable result is not possible'). In practice this means an embeddable (often a nested one) was used in a position where its owning entity/collection is not part of the result graph.","triggerScenarios":"Selecting an embeddable directly as the query return or projection (e.g. `select o.address from Order o`, or a criteria query whose selection is the embeddable path) such that the embeddable initializer is at/near the root of the result graph; nested embeddables (embeddable inside embeddable) reached without their owning entity in the same result; embeddables with @Parent injection used in report projections.","commonSituations":"Migrating Hibernate 5.x applications to 6.x where the results-graph was rewritten and some direct embeddable selections are no longer supported; DTO-style queries that try to project component types instead of their attributes; criteria queries built dynamically that end up selecting an embeddable node.","solutions":["Select the owning entity instead and read the embeddable from it (select o from Order o, then o.getAddress()).","Project the embeddable's individual attributes as scalars, or use a constructor expression `select new com.acme.AddressDto(a.street, a.city) ...` targeting a DTO class.","If you need the embeddable type itself, map a dedicated DTO with a matching constructor instead of reusing the @Embeddable class in projections.","Upgrade to the latest 6.x patch - support for embeddable DomainResults has been progressively improved; check the release notes for your exact scenario."],"exampleFix":"// before (embeddable selected directly - unsupported position)\nList<Address> addrs = em.createQuery(\"select o.address from Order o\", Address.class).getResultList();\n\n// after\nList<AddressDto> addrs = em.createQuery(\n    \"select new com.acme.AddressDto(a.street, a.city) from Order o join o.address a\",\n    AddressDto.class).getResultList();","handlingStrategy":"try-catch","validationCode":"// Before running the projection, confirm the query selects an entity-managed type, not a bare embeddable\nif (Address.class.isAnnotationPresent(Embeddable.class)) {\n    throw new IllegalArgumentException(\"Select the owning entity or a DTO; bare embeddable projections are unsupported\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    List<Address> r = em.createQuery(\"select o.address from Order o\", Address.class).getResultList();\n} catch (UnsupportedOperationException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"parent instance into embeddable\")) {\n        // restructure: project scalars or a DTO instead\n    } else { throw e; }\n}","preventionTips":["Never select an @Embeddable path directly; select the owning entity or project its attributes.","Use DTO classes (not @Embeddable types) for report projections.","Keep integration tests for every query shape you ship; upgrade tests catch 6.x results-graph changes."],"tags":["hibernate","orm","embeddable","query-projection","unsupported-operation","migration"],"backgroundTag":"embeddable-parent-injection","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}