{"record":{"id":"99ad452d1d1cb7fb","repo":"hibernate/hibernate-orm","slug":"wrap-strategy-not-known-for-this-java-type-ge","errorCode":null,"errorMessage":"Wrap strategy not known for this Java type: \" + getTypeName()","messagePattern":"Wrap strategy not known for this Java type: \" \\+ getTypeName\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/EmbeddableAggregateJavaType.java","lineNumber":90,"sourceCode":"\t\tif ( type.isAssignableFrom( getJavaTypeClass() ) ) {\n\t\t\treturn type.cast( value );\n\t\t}\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\t\"Unwrap strategy not known for this Java type: \" + getTypeName()\n\t\t);\n\t}\n\n\t@Override\n\tpublic <X> T wrap(X value, WrapperOptions options) {\n\t\tif ( value == null ) {\n\t\t\treturn null;\n\t\t}\n\t\telse {\n\t\t\tfinal var javaTypeClass = getJavaTypeClass();\n\t\t\tif ( javaTypeClass.isInstance( value ) ) {\n\t\t\t\treturn javaTypeClass.cast( value );\n\t\t\t}\n\t\t\tthrow new UnsupportedOperationException(\n\t\t\t\t\t\"Wrap strategy not known for this Java type: \" + getTypeName()\n\t\t\t);\n\t\t}\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"BasicJavaType(\" + getTypeName() + \")\";\n\t}\n}\n","sourceCodeStart":72,"sourceCodeEnd":101,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/EmbeddableAggregateJavaType.java#L72-L101","documentation":"The mirror of unwrap: wrap() accepts only null or instances of the embeddable class itself. Reading an aggregate column yields the deserialized embeddable; handing wrap() anything else — a JSON String, a Map, a driver PGobject — throws UnsupportedOperationException because the JavaType does no parsing.","triggerScenarios":"Custom result-set extraction calling javaType.wrap(rs.getString(...), options); converters feeding pre-serialized JSON back into wrap; hydrating driver-specific JSONB objects directly.","commonSituations":"Hand-written JDBC readers for JSON columns; migration of legacy Hibernate 5 UserType code; generic hydration frameworks that try wrap() first with whatever object they hold.","solutions":["Pass the deserialized embeddable instance (or null), never its serialized form","Deserialize first with the FormatMapper: mapper.fromString(rs.getString(...), javaType, options)","Let the standard JsonJdbcType extractor drive hydration so wrap() only ever sees typed objects"],"exampleFix":"// before\nAddress a = embeddableJavaType.wrap(rs.getString(\"address\"), options); // String is not an Address -> throws\n\n// after\nAddress a = formatMapper.fromString(rs.getString(\"address\"), embeddableJavaType, options);\n// or simply rely on the annotated attribute's own JsonJdbcType binding","handlingStrategy":"type-guard","validationCode":"static Object safeWrap(JavaType<?> jt, Object raw, WrapperOptions options) {\n    if (raw == null || jt.getJavaTypeClass().isInstance(raw)) {\n        return jt.wrap(jt.getJavaTypeClass().cast(raw), options);\n    }\n    return null; // or deserialize via FormatMapper first\n}","typeGuard":"static boolean wrapSupported(JavaType<?> jt, Object value) {\n    return value == null || jt.getJavaTypeClass().isInstance(value);\n}","tryCatchPattern":"try {\n    T v = javaType.wrap(raw, options);\n} catch (UnsupportedOperationException e) {\n    // deserialize the JSON yourself, then hand the typed object back\n    T v = formatMapper.fromString((String) raw, javaType, options);\n}","preventionTips":["Hydrate aggregate columns through FormatMapper.fromString, never JavaType.wrap","Keep custom extractors aligned with the JdbcType contract","Cover wrap paths in custom-type contract tests"],"tags":["hibernate","orm","wrap","embeddable","json"],"backgroundTag":"unsupported-type-conversion","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}