hibernate/hibernate-orm · error · UnsupportedOperationException
Support for model part type not yet implemented:
Error message
Support for model part type not yet implemented:
What it means
While flattening an embeddable into JSON, serializeObjectValues walks each sub-part (getSubPart) and hands it to serializeModelPart. Only two model-part shapes are serializable: SelectableMapping (plain column-backed values, written as key + visit) and EmbeddedAttributeMapping (nested embeddables). Anything else - to-one associations, plural attributes, @Any mappings, custom ValuedModelPart implementations - has no JSON key/value form, so Hibernate throws UnsupportedOperationException with the model part class name, or 'null' when the part itself is null.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/spi/JsonGeneratingVisitor.java:269
visit( modelPart.getMappedType(), value, options, writer );
}
else if ( modelPart instanceof EmbeddedAttributeMapping embeddedAttribute ) {
if ( value != null ) {
final EmbeddableMappingType mappingType = embeddedAttribute.getMappedType();
final SelectableMapping aggregateMapping = mappingType.getAggregateMapping();
if ( aggregateMapping == null ) {
serializeObjectValues( mappingType, value, options, writer );
}
else {
final String name = aggregateMapping.getSelectableName();
writer.objectKey( name );
visit( mappingType, value, options, writer );
}
}
}
else {
// could not handle model part, throw exception
throw new UnsupportedOperationException(
"Support for model part type not yet implemented: "
+ (modelPart != null ? modelPart.getClass().getName() : "null")
);
}
}
protected void serializeEntity(
Object value,
EntityMappingType entityType,
WrapperOptions options,
JsonDocumentWriter writer) throws IOException {
// We only need the identifier here
final EntityIdentifierMapping identifierMapping = entityType.getIdentifierMapping();
serializeEntityIdentifier( value, identifierMapping, options, writer );
}
protected void serializeEntityIdentifier(
Object value,View on GitHub (pinned to fad1729dce)
Solutions
- Remove the association field from the JSON-mapped embeddable or annotate it @Transient
- Replace the association inside the embeddable with a plain FK column (e.g. Long otherId), which is a basic SelectableMapping and serializes fine
- Keep associations on the owning entity instead of inside the aggregate
- Upgrade Hibernate ORM in case additional model parts became serializable
Example fix
// before
@Embeddable
class Address {
@ManyToOne
private Country country; // association inside JSON aggregate -> 'Support for model part type not yet implemented'
}
// after
@Embeddable
class Address {
@Column(name = "country_id")
private Long countryId; // basic FK column serializes as a JSON value
} Defensive patterns
Strategy: validation
Validate before calling
// Fail fast at startup: scan embeddables used in JSON aggregates for association fields
for (Field f : embeddableClass.getDeclaredFields()) {
if (f.isAnnotationPresent(ManyToOne.class) || f.isAnnotationPresent(OneToOne.class)
|| f.isAnnotationPresent(Any.class) || f.isAnnotationPresent(OneToMany.class)
|| f.isAnnotationPresent(ManyToMany.class)) {
if (!f.isAnnotationPresent(Transient.class)) {
throw new IllegalStateException("Association inside JSON-mapped embeddable: " + f);
}
}
} Prevention
- Keep associations out of embeddables stored as JSON - store plain FK columns instead
- Mark non-persisted helper fields @Transient
- Round-trip every aggregate mapping (persist + load) in integration tests before shipping
When it happens
Trigger: An @Embeddable stored as a JSON aggregate (e.g. @JdbcTypeCode(SqlTypes.JSON) on an @Embedded attribute for PostgreSQL jsonb / Oracle JSON) that declares @ManyToOne, @OneToOne, @Any or a collection field; during flush or query-result writing the association's model part (e.g. ToOneAttributeMapping) reaches serializeModelPart and is rejected.
Common situations: Reusing domain embeddables originally written for plain relational mapping inside JSON columns; retrofitting JSON storage onto an existing model that keeps entity references inside value objects.
Related errors
- Could not find selectable [%s] in embeddable type [%s] for J
- Can't parse JSON object for selectable [%s] which is not of
- Failed to serialize JSON mapping
- Unsupported foreign key part:
- Unwrap strategy not known for this Java type: " + getTypeNam
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/5ae22b35bce18870.
Report an issue: GitHub.