{"record":{"id":"c2f1ba2d491e4cc8","repo":"hibernate/hibernate-orm","slug":"jdbc-type-code-s-s-not-known-to-have-a-corre-c2f1ba","errorCode":null,"errorMessage":"JDBC type-code [%s (%s)] not known to have a corresponding LOB equivalent","messagePattern":"JDBC type-code \\[(.+?) \\((.+?)\\)\\] not known to have a corresponding LOB equivalent","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/LobTypeMappings.java","lineNumber":51,"sourceCode":"\t\t\t\tjdbcTypeCode == Types.LONGVARCHAR ||\n\n\t\t\t\t// NCLOB mappings\n\t\t\t\tjdbcTypeCode == Types.NCLOB ||\n\t\t\t\tjdbcTypeCode == Types.NCHAR ||\n\t\t\t\tjdbcTypeCode == Types.NVARCHAR ||\n\t\t\t\tjdbcTypeCode == Types.LONGNVARCHAR;\n\t}\n\n\tpublic static int getLobCodeTypeMapping(final int jdbcTypeCode) {\n\t\treturn switch ( jdbcTypeCode ) {\n\t\t\t// BLOB mappings\n\t\t\tcase Types.BLOB, Types.BINARY, Types.VARBINARY, Types.LONGVARBINARY -> Types.BLOB;\n\t\t\t// CLOB mappings\n\t\t\tcase Types.CLOB, Types.CHAR, Types.VARCHAR, Types.LONGVARCHAR -> Types.CLOB;\n\t\t\t// NCLOB mappings\n\t\t\tcase Types.NCLOB, Types.NCHAR, Types.NVARCHAR, Types.LONGNVARCHAR -> Types.NCLOB;\n\t\t\t// Anything else:\n\t\t\tdefault -> throw new IllegalArgumentException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\tLocale.ROOT,\n\t\t\t\t\t\t\t\"JDBC type-code [%s (%s)] not known to have a corresponding LOB equivalent\",\n\t\t\t\t\t\t\tjdbcTypeCode,\n\t\t\t\t\t\t\tJdbcTypeNameMapper.getTypeName( jdbcTypeCode )\n\t\t\t\t\t) );\n\t\t};\n\t}\n}\n","sourceCodeStart":33,"sourceCodeEnd":61,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/LobTypeMappings.java#L33-L61","documentation":"LobTypeMappings.getLobCodeTypeMapping() answers the LOB-equivalent java.sql.Types code for exactly three families: binary (BLOB/BINARY/VARBINARY/LONGVARBINARY -> BLOB), char (CLOB/CHAR/VARCHAR/LONGVARCHAR -> CLOB) and nchar (NCLOB/NCHAR/NVARCHAR/LONGNVARCHAR -> NCLOB). Any other code has no LOB variant and throws IllegalArgumentException naming the offending code and type name.","triggerScenarios":"Calling getLobCodeTypeMapping() (directly, or through dialect/type-building code that materializes LOB variants, e.g. wrapping a type as LOB or nationalized) with a non-lob-family code such as Types.INTEGER, Types.DATE, Types.ARRAY or Types.STRUCT.","commonSituations":"Custom dialects or integrators that blindly derive a LOB variant for every JDBC type; programmatic type building with SqlTypes codes fed into the LOB helper; copy-pasted type-contribution code assuming all codes have LOB equivalents.","solutions":["Guard the call with LobTypeMappings.isMappedToKnownLobCode(jdbcTypeCode) and only derive LOB variants for the binary/char/nchar families.","If a LOB was intended, map the attribute explicitly to Types.BLOB/CLOB/NCLOB instead of deriving it from a non-lob code.","Audit custom dialect/type code for unconditional calls to getLobCodeTypeMapping()."],"exampleFix":"// before\nint lobCode = LobTypeMappings.getLobCodeTypeMapping(jdbcTypeCode); // throws for Types.INTEGER\n\n// after: only LOB families have equivalents\nif (LobTypeMappings.isMappedToKnownLobCode(jdbcTypeCode)) {\n    int lobCode = LobTypeMappings.getLobCodeTypeMapping(jdbcTypeCode);\n}","handlingStrategy":"type-guard","validationCode":"// Guard the LOB derivation with the family check Hibernate provides\nif (LobTypeMappings.isMappedToKnownLobCode(jdbcTypeCode)) {\n    int lobCode = LobTypeMappings.getLobCodeTypeMapping(jdbcTypeCode);\n    // ... build the LOB variant\n} else {\n    // no LOB equivalent exists for this code - keep the original type\n}","typeGuard":"static boolean hasLobEquivalent(int jdbcTypeCode) {\n    return LobTypeMappings.isMappedToKnownLobCode(jdbcTypeCode);\n}","tryCatchPattern":"try {\n    return LobTypeMappings.getLobCodeTypeMapping(jdbcTypeCode);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"not known to have a corresponding LOB equivalent\")) {\n        // this jdbcTypeCode has no LOB variant: map to BLOB/CLOB/NCLOB explicitly if a LOB was intended\n    } else {\n        throw e;\n    }\n}","preventionTips":["Never call LOB-variant derivation for non-binary/non-char type codes","Unit-test custom dialect/type code against the full SqlTypes set","Map intended LOBs explicitly instead of deriving them"],"tags":["hibernate","lob","jdbc-type","dialect","type-mapping"],"backgroundTag":"invalid-jdbc-type-code","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}