{"record":{"id":"97e3b7c198e91dd7","repo":"hibernate/hibernate-orm","slug":"unable-to-access-jdbc-type-mapping-field-getn","errorCode":null,"errorMessage":"Unable to access JDBC type mapping [\" + field.getName() + \"]","messagePattern":"Unable to access JDBC type mapping \\[\" \\+ field\\.getName\\(\\) \\+ \"\\]","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"warning","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/JdbcTypeNameMapper.java","lineNumber":54,"sourceCode":"\t\t\t\t\tCORE_LOGGER.JavaSqlTypesMappedSameCodeMultipleTimes( code, old, field.getName() );\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch ( IllegalAccessException e ) {\n\t\t\t\tthrow new HibernateException( \"Unable to access JDBC type mapping [\" + field.getName() + \"]\", e );\n\t\t\t}\n\t\t}\n\t\treturn unmodifiableMap( map );\n\t}\n\n\tprivate static Map<String, Integer> buildJdbcTypeNameMap(Class<?> typesClass) {\n\t\tfinal HashMap<String, Integer> map = new HashMap<>();\n\t\tfor ( Field field : typesClass.getFields() ) {\n\t\t\ttry {\n\t\t\t\tfinal int code = field.getInt( null );\n\t\t\t\tmap.put( field.getName(), code );\n\t\t\t}\n\t\t\tcatch ( IllegalAccessException e ) {\n\t\t\t\tthrow new HibernateException( \"Unable to access JDBC type mapping [\" + field.getName() + \"]\", e );\n\t\t\t}\n\t\t}\n\t\treturn unmodifiableMap( map );\n\t}\n\n\t/**\n\t * Determine whether the given JDBC type code represents a standard JDBC type\n\t * (\"standard\" being those defined on {@link java.sql.Types}).\n\t *\n\t * @implNote {@link java.sql.Types#OTHER} is also \"filtered out\" as being non-standard.\n\t *\n\t * @param typeCode The JDBC type code to check\n\t *\n\t * @return {@code true} to indicate the type code is a standard type code; {@code false} otherwise.\n\t */\n\tpublic static boolean isStandardTypeCode(int typeCode) {\n\t\treturn isStandardTypeCode( Integer.valueOf( typeCode ) );\n\t}","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/JdbcTypeNameMapper.java#L36-L72","documentation":"JdbcTypeNameMapper.buildJdbcTypeNameMap (JdbcTypeNameMapper.java:44-58) reflects over the public static int fields of java.sql.Types to build a name-to-code map; an IllegalAccessException while reading a field is wrapped in HibernateException 'Unable to access JDBC type mapping [<field>]'. Public static fields of java.sql.Types are accessible on every stock JDK, so hitting this means an unusual runtime: a restrictive security manager, a patched/shaded java.sql.Types, or bytecode instrumentation interfering with reflection.","triggerScenarios":"Running under a SecurityManager / custom policy that denies reflective access to java.sql; deploying a JDK or driver jar where java.sql.Types was rebuilt/shaded with non-public fields; Java agents or AOP/coverage tools weaving java.sql and breaking reflection; unit tests mocking java.sql.Types via agent-based frameworks.","commonSituations":"Legacy application-server security policies; shading/uber-jar builds that relocate or stub JDK classes (rare but seen with broken relocation rules); debugging environments with aggressive instrumentation (JaCoCo on JDK internals, hostile mocks); practically never on a standard JDK.","solutions":["Verify the runtime JDK: run with an unmodified JDK distribution and a recent Hibernate; try another JDK build to rule out a patched java.sql.","If a security manager/policy is active, allow reflective access to java.sql (or remove the policy) and retry.","Disable or reconfigure shading/bytecode agents that touch java.sql, and check the uber-jar for relocated JDK classes.","If reproducible on a stock JDK, capture the full stack trace and report it as a Hibernate JIRA issue with the JDK vendor/version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Fail fast with a clear message if JDK reflection is restricted\ntry {\n    Field f = java.sql.Types.class.getField(\"VARCHAR\");\n    f.getInt(null);\n} catch (Exception e) {\n    throw new IllegalStateException(\n        \"java.sql.Types reflection is blocked in this runtime; JdbcTypeNameMapper will fail\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    // operation that may log/resolve JDBC type names (exception formatting, schema export)\n    new SchemaExport().createOnly(EnumSet.of(TargetType.DATABASE), metadata);\n} catch (HibernateException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to access JDBC type mapping\")) {\n        // environment defect: run on an unmodified JDK / relax the security policy, then retry\n        log.error(\"Blocked reflection on java.sql.Types - check JDK/security manager\", e);\n    }\n    throw e;\n}","preventionTips":["Pin builds and deploys to unmodified JDK distributions; audit uber-jar relocation rules that could touch java.sql.","When running with restrictive security policies or instrumentation agents, smoke-test Hibernate bootstrap in that exact environment."],"tags":["hibernate","jdbc","reflection","jdk","environment"],"backgroundTag":"reflection-access-denied","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}