hibernate/hibernate-orm · error · IllegalArgumentException

Unexpected non-null value for embeddable subtype '%s'

Error message

Unexpected non-null value for embeddable subtype '%s'

What it means

Error "Unexpected non-null value for embeddable subtype '%s'" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java:901

			return results;
		}
	}

	@Override
	protected void setAttributeValues(Object component, Object[] values) {
		if ( !isPolymorphic() ) {
			super.setAttributeValues( component, values );
		}
		else {
			final String compositeClassName = component.getClass().getName();
			final var concreteEmbeddableType = findSubtypeBySubclass( compositeClassName );
			for ( int i = 0; i < getNumberOfAttributeMappings(); i++ ) {
				final AttributeMapping attributeMapping = getAttributeMapping( i );
				if ( concreteEmbeddableType.declaresAttribute( attributeMapping ) ) {
					setValue( component, i, values[i] );
				}
				else if ( values[i] != null ) {
					throw new IllegalArgumentException( String.format(
							"Unexpected non-null value for embeddable subtype '%s'",
							compositeClassName
					) );
				}
			}
		}
	}

	@Override
	public ModelPart findSubPart(String name, EntityMappingType treatTargetType) {
		return EntityDiscriminatorMapping.matchesRoleName( name )
				? discriminatorMapping
				: super.findSubPart( name, treatTargetType );

	}

	@Override
	public <X, Y> int breakDownJdbcValues(

View on GitHub (pinned to fad1729dce)

Solutions

  1. Set only the discriminator-selected subtype's portion of the embeddable; do not populate values for other subtypes.

When it happens

Trigger: Thrown when materializing an embeddable whose discriminator indicates one subtype but a non-null value is found for a different subtype's state.

Common situations: See trigger scenarios.


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