hibernate/hibernate-orm · error · IllegalStateException
no object key available
Error message
no object key available
What it means
OsonDocumentReader.getObjectKeyName() returns the current key name only right after the parser produced a KEY_NAME event (mapped to JsonDocumentItemType.VALUE_KEY): next() resets currentKeyName to null and only the KEY_NAME branch sets it. Calling the accessor at any other position in the iteration throws IllegalStateException 'no object key available'.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/type/format/OsonDocumentReader.java:109
return JsonDocumentItemType.VALUE;
case VALUE_DOUBLE:
currentValue = this.parser.getDouble();
return JsonDocumentItemType.VALUE;
case VALUE_FLOAT:
currentValue = this.parser.getFloat();
return JsonDocumentItemType.VALUE;
case VALUE_BINARY:
currentValue = this.parser.getBytes();
return JsonDocumentItemType.VALUE;
default :
throw new IllegalStateException( "Unknown OSON event: " + evt );
}
}
@Override
public String getObjectKeyName() {
if (currentKeyName == null)
throw new IllegalStateException("no object key available");
return currentKeyName;
}
@Override
public String getStringValue() {
return (String)currentValue;
}
@Override
public BigDecimal getBigDecimalValue() {
return (BigDecimal)currentValue;
}
@Override
public BigInteger getBigIntegerValue() {
return ((BigDecimal)currentValue).toBigInteger();
}
View on GitHub (pinned to fad1729dce)
Solutions
- Only call getObjectKeyName() immediately after next() returned the object-key item type
- Track the last returned JsonDocumentItemType in your loop and gate key/value accessors on it
- Read payloads via the typed getters (getStringValue/getBigDecimalValue/...) only after VALUE items
Example fix
// before
reader.next();
String key = reader.getObjectKeyName(); // throws if last item was not a key
// after
if (reader.next() == JsonDocumentItemType.VALUE_KEY) {
String key = reader.getObjectKeyName();
} Defensive patterns
Strategy: validation
Validate before calling
JsonDocumentItemType last = null;
while (reader.hasNext()) {
last = reader.next();
if (last == JsonDocumentItemType.VALUE_KEY) {
String key = reader.getObjectKeyName(); // only valid here
}
} Prevention
- Read the interface contract: accessors are valid only immediately after the matching next()
- Gate every typed accessor on the last returned JsonDocumentItemType
- Centralize reader traversal in one adapter class instead of sprinkling next()/getObjectKeyName() calls
When it happens
Trigger: Calling getObjectKeyName() when the last next() returned anything other than the key item type - e.g. while iterating array elements, before the first next(), or after consuming the key and its value.
Common situations: Custom adapters or integration code driving JsonDocumentReader; porting Jackson-style code where field names are always available; test harnesses that call accessors eagerly.
Related errors
- Unsupportd target type
- Unsupportd source type
- No more item in JSON document
- Unknown OSON event: {}
- Unsupported numeric type: {}
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/305754aba9507b3a.
Report an issue: GitHub.