hibernate/hibernate-orm · error · IllegalArgumentException

Can't parse JSON object for selectable [%s] which is not of

Error message

Can't parse JSON object for selectable [%s] which is not of type AggregateJdbcType.

What it means

While parsing a JSON document into an embeddable, encountering OBJECT_START for a selectable whose JdbcType is not an AggregateJdbcType throws IllegalArgumentException - the document has a nested JSON object where the mapping expects a basic/scalar value (nested objects are only legal for nested embeddables mapped as aggregates).

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JsonHelper.java:132

				case ARRAY_END -> {
					assert currentLevel.arrayType != null;
					assert currentLevel.selectableData != null;

					parseLevel.pop();
					final ParseLevel parentLevel = parseLevel.getCurrent();

					assert parentLevel.embeddableMappingType != null;
					// flush array values
					parentLevel.addValue(
							currentLevel.selectableData,
							currentLevel.arrayType.getJdbcJavaType().wrap( currentLevel.subArrayObjectList, options )
					);
				}
				case OBJECT_START -> {
					final JdbcMapping jdbcMapping = currentLevel.determineJdbcMapping( currentSelectableData );

					if ( !(jdbcMapping.getJdbcType() instanceof AggregateJdbcType aggregateJdbcType) ) {
						throw new IllegalArgumentException(
								String.format(
										"Can't parse JSON object for selectable [%s] which is not of type AggregateJdbcType.",
										ParseLevel.determineSelectablePath( parseLevel, currentSelectableData )
								)
						);
					}
					parseLevel.push(
							new ParseLevel( currentSelectableData, aggregateJdbcType.getEmbeddableMappingType() ) );
					currentSelectableData = null;
				}
				case OBJECT_END -> {
					final EmbeddableMappingType currentEmbeddableMappingType = currentLevel.embeddableMappingType;
					assert currentEmbeddableMappingType != null;

					// go back in the mapping definition tree
					parseLevel.pop();
					final Object objectValue;
					if ( returnEmbeddable ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Model the nested object: add an @Embeddable class for it and annotate the attribute so it is aggregate-mapped (@Embedded + json/struct mapping), making its JdbcType an AggregateJdbcType.
  2. Or flatten the stored data so the key holds a scalar instead of an object.

Example fix

// before: stored {"price":{"amount":1.0,"currency":"EUR"}} but attribute is scalar
@Embeddable public class Product { BigDecimal price; }
// load -> Can't parse JSON object for selectable [price]

// after: map the nested object as an aggregate embeddable
@Embeddable public class Product {
    @Embedded
    Money price;   // @Embeddable class Money { BigDecimal amount; String currency; }
}
Defensive patterns

Strategy: validation

Validate before calling

// Check nested objects only appear under aggregate-mapped keys (Jackson example)
static void assertObjectsOnlyOnAggregateKeys(JsonNode doc, Set<String> aggregateKeys) {
    doc.fields().forEachRemaining(entry -> {
        if (entry.getValue().isObject() && !aggregateKeys.contains(entry.getKey())) {
            throw new IllegalStateException("Key '" + entry.getKey() + "' holds an object but is not an aggregate/embeddable");
        }
    });
}

Try / catch

try {
    return session.find(Product.class, id);
} catch (IllegalArgumentException e) {
    if (e.getMessage() != null && e.getMessage().contains("not of type AggregateJdbcType")) {
        // nested object vs scalar mapping: add an @Embeddable for it or flatten the data
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Loading a json/struct aggregate mapping where the stored document nests an object under a key mapped to a scalar attribute; e.g., {"price":{"amount":1,"currency":"EUR"}} while 'price' is mapped as a plain BigDecimal column, not an embedded Money type.

Common situations: Refactoring an embeddable by flattening or un-flattening nested objects without migrating stored JSON; multiple writers (some embedding, some not) sharing the column.

Related errors


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