hibernate/hibernate-orm · error · UnsupportedOperationException

Injection of parent instance into embeddable result is not p

Error message

Injection of parent instance into embeddable result is not possible

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/internal/EmbeddableInitializerImpl.java:562

				assert setter != null;
				setter.set( data.getInstance(), parent );
			}
		}
		// else embeddable defined no parent injection
	}

	private Initializer<?> determineOwningInitializer() {
		// Try to find the first non-embeddable fetch parent access
		// todo (6.x) - allow injection of containing composite as parent if
		//  	it is the direct parent
		InitializerParent<?> parent = this.parent;
		while ( parent != null ) {
			if ( !parent.isEmbeddableInitializer() ) {
				return parent;
			}
			parent = parent.getParent();
		}
		throw new UnsupportedOperationException( "Injection of parent instance into embeddable result is not possible" );
	}

	private Object determineParentInstance(Initializer<?> parentInitializer, RowProcessingState rowProcessingState) {
		if ( parentInitializer == null ) {
			throw new UnsupportedOperationException( "Cannot determine Embeddable: " + navigablePath + " parent instance, parent initializer is null" );
		}

		final var collectionInitializer = parentInitializer.asCollectionInitializer();
		if ( collectionInitializer != null ) {
			return collectionInitializer.getCollectionInstance( rowProcessingState ).getOwner();
		}

		final var parentEntityInitializer = parentInitializer.asEntityInitializer();
		if ( parentEntityInitializer != null ) {
			return parentEntityInitializer.getTargetInstance( rowProcessingState );
		}

		throw new UnsupportedOperationException( "The Embeddable: " + navigablePath + " parent initializer is neither an instance of an EntityInitializer nor of a CollectionInitializer" );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Select the owning entity instead and read the embeddable from it (select o from Order o, then o.getAddress()).
  2. 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.
  3. If you need the embeddable type itself, map a dedicated DTO with a matching constructor instead of reusing the @Embeddable class in projections.
  4. Upgrade to the latest 6.x patch - support for embeddable DomainResults has been progressively improved; check the release notes for your exact scenario.

Example fix

// before (embeddable selected directly - unsupported position)
List<Address> addrs = em.createQuery("select o.address from Order o", Address.class).getResultList();

// after
List<AddressDto> addrs = em.createQuery(
    "select new com.acme.AddressDto(a.street, a.city) from Order o join o.address a",
    AddressDto.class).getResultList();
Defensive patterns

Strategy: try-catch

Validate before calling

// Before running the projection, confirm the query selects an entity-managed type, not a bare embeddable
if (Address.class.isAnnotationPresent(Embeddable.class)) {
    throw new IllegalArgumentException("Select the owning entity or a DTO; bare embeddable projections are unsupported");
}

Try / catch

try {
    List<Address> r = em.createQuery("select o.address from Order o", Address.class).getResultList();
} catch (UnsupportedOperationException e) {
    if (e.getMessage() != null && e.getMessage().contains("parent instance into embeddable")) {
        // restructure: project scalars or a DTO instead
    } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/f1ab70adce8d1e60. Report an issue: GitHub.