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
The descriptive JSON serializer handles four model-part kinds: basic selectables, embedded attributes, entity-valued parts, and plural attributes. Any other ModelPart on the entity path - most commonly a @Any DiscriminatedAssociationAttributeMapping - throws UnsupportedOperationException with the part class name (or 'null').
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/spi/DescriptiveJsonGeneratingVisitor.java:124
if ( modelPart instanceof SelectableMapping ) {
writer.objectKey( modelPart.getPartName() );
visit( modelPart.getMappedType(), value, options, writer );
}
else if ( modelPart instanceof EmbeddedAttributeMapping embeddedAttribute ) {
writer.objectKey( embeddedAttribute.getAttributeName() );
visit( embeddedAttribute.getMappedType(), value, options, writer );
}
else if ( modelPart instanceof EntityValuedModelPart entityPart ) {
writer.objectKey( entityPart.getPartName() );
visit( entityPart.getEntityMappingType(), value, options, writer );
}
else if ( modelPart instanceof PluralAttributeMapping plural ) {
writer.objectKey( plural.getPartName() );
serializePluralAttribute( value, plural, 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")
);
}
}
private void serializePluralAttribute(
Object value,
PluralAttributeMapping plural,
WrapperOptions options,
JsonDocumentWriter writer) throws IOException {
if ( handleNullOrLazy( value, writer ) ) {
// nothing left to do
return;
}
final CollectionPart element = plural.getElementDescriptor();
final CollectionSemantics<?, ?> collectionSemantics = plural.getMappedType().getCollectionSemantics();View on GitHub (pinned to fad1729dce)
Solutions
- Replace the @Any mapping with a regular @ManyToOne to a mapped hierarchy.
- Exclude entities carrying @Any from descriptive JSON export (select a projection instead).
- Upgrade Hibernate: visitor coverage expands over versions; report the missing part class in a Jira issue.
Example fix
// before @Any @JoinColumn(name = "owner_id") @AnyDiscriminator(DiscriminatorType.STRING) @AnyKeyJavaType(Long.class) private Serializable owner; // -> Support for model part type not yet implemented // after: plain association to a mapped hierarchy @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "owner_id") private Party owner;
Defensive patterns
Strategy: validation
Validate before calling
static void assertDescriptiveSerializable(Class<?> entity) {
for (Field f : entity.getDeclaredFields()) {
if (f.isAnnotationPresent(Any.class)) {
throw new IllegalStateException(
"@Any attribute not supported by descriptive JSON: " + f);
}
}
} Try / catch
try {
return resultsJsonSerializer.toJson(resultList);
} catch (UnsupportedOperationException ex) {
if (ex.getMessage() != null && ex.getMessage().startsWith("Support for model part type")) {
// entity carries an exotic part (e.g. @Any); fall back to a projection
return serializeProjection(resultList);
}
throw ex;
} Prevention
- Prefer regular @ManyToOne associations over @Any on entities exposed to tooling serialization.
- Smoke-test descriptive JSON export against the real entity metamodel after model changes.
- Track Hibernate release notes for visitor coverage of new model-part kinds.
When it happens
Trigger: Hibernate Assistant (or any consumer of DescriptiveJsonGeneratingVisitor) serializes an entity that contains an @Any or @AnyDiscriminator mapping, or another exotic model part not covered by the four supported kinds.
Common situations: Entities with polymorphic @Any references included in query results exported to JSON; enriching legacy models with any-style associations; new Hibernate versions adding model-part kinds the visitor has not learned yet.
Related errors
- Error serializing entity
- Failed to serialize JSON mapping
- Could not serialize array element
- Unsupported numeric type: {}
- array case should be treated at upper level
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/d0b5bc86fce81a88.
Report an issue: GitHub.