{"record":{"id":"a1771cbdc401b8bc","repo":"hibernate/hibernate-orm","slug":"no-more-item-in-json-document","errorCode":null,"errorMessage":"No more item in JSON document","messagePattern":"No more item in JSON document","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/format/OsonDocumentReader.java","lineNumber":48,"sourceCode":"\tprivate Object currentValue;\n\n\t/**\n\t * Creates a new <code>OsonDocumentReader</code>  on top of a <code>OracleJsonParser</code>\n\t * @param parser the parser\n\t */\n\tpublic OsonDocumentReader(OracleJsonParser parser) {\n\t\tthis.parser = parser;\n\t}\n\n\t@Override\n\tpublic boolean hasNext() {\n\t\treturn this.parser.hasNext();\n\t}\n\n\t@Override\n\tpublic JsonDocumentItemType next() {\n\t\tif (!this.parser.hasNext())\n\t\t\tthrow new NoSuchElementException(\"No more item in JSON document\");\n\t\tOracleJsonParser.Event evt = this.parser.next();\n\t\tcurrentKeyName = null;\n\t\tcurrentValue = null;\n\t\tswitch (evt) {\n\t\t\tcase START_OBJECT:\n\t\t\t\treturn JsonDocumentItemType.OBJECT_START;\n\t\t\tcase END_OBJECT:\n\t\t\t\treturn JsonDocumentItemType.OBJECT_END;\n\t\t\tcase START_ARRAY:\n\t\t\t\treturn JsonDocumentItemType.ARRAY_START;\n\t\t\tcase END_ARRAY:\n\t\t\t\treturn JsonDocumentItemType.ARRAY_END;\n\t\t\tcase KEY_NAME:\n\t\t\t\tcurrentKeyName = this.parser.getString();\n\t\t\t\treturn JsonDocumentItemType.VALUE_KEY;\n\t\t\tcase VALUE_TIMESTAMPTZ:\n\t\t\t\tcurrentValue = this.parser.getOffsetDateTime();\n\t\t\t\treturn JsonDocumentItemType.VALUE;","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/format/OsonDocumentReader.java#L30-L66","documentation":"OsonDocumentReader wraps Oracle's OracleJsonParser for binary OSON documents. next() defensively re-checks parser.hasNext() and throws NoSuchElementException 'No more item in JSON document' when the caller drains past the end - in Hibernate-driven reads this means the embeddable mapping's structure expectation (driven by getAdapter) wants more events than the stored document actually contains.","triggerScenarios":"Reading an Oracle JSON aggregate column whose stored document is truncated or shaped differently from the mapping (fewer object/array entries than the embeddable expects), so the adapter calls next() after the parser is exhausted; also direct API misuse (next() without hasNext()).","commonSituations":"Corrupt or hand-edited JSON/OSON data; documents written by other services with a different schema version; mapping changes across deployments; Oracle OSON round-trips with mixed tooling.","solutions":["When driving the reader directly, guard every next() with hasNext()","Validate the stored documents (Oracle IS JSON check / jsonb validation, or a Jackson parse) and repair malformed rows","Align the embeddable mapping with the actual document structure - missing keys are fine (nulls), but structural tokens must match","Catch NoSuchElementException during aggregate reads and rethrow as a data-quality error identifying the row"],"exampleFix":"// before\nwhile (true) {\n    JsonDocumentItemType item = reader.next(); // throws 'No more item in JSON document' at end\n}\n\n// after\nwhile (reader.hasNext()) {\n    JsonDocumentItemType item = reader.next();\n}","handlingStrategy":"try-catch","validationCode":"while (reader.hasNext()) { // guard every next() when driving the reader directly\n    JsonDocumentItemType item = reader.next();\n}","typeGuard":null,"tryCatchPattern":"try {\n    MyAgg agg = session.find(MyEntity.class, id).getAgg();\n} catch (NoSuchElementException e) {\n    throw new DataIntegrityViolationException(\"Truncated/malformed JSON document in row \" + id, e);\n}","preventionTips":["Validate JSON columns with a constraint (Oracle IS JSON / PostgreSQL jsonb type) so bad data cannot enter","Version aggregate document schemas alongside the entities that read them","Wrap aggregate reads to translate NoSuchElementException into a data-quality error with row identity"],"tags":["hibernate","oracle","oson","json","data-corruption","iterator"],"backgroundTag":"json-iterator-exhausted","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}