{"record":{"id":"a4053196cedbccd6","repo":"hibernate/hibernate-orm","slug":"unable-to-initialize-eventtype-map","errorCode":null,"errorMessage":"Unable to initialize EventType map","messagePattern":"Unable to initialize EventType map","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"critical","filePath":"hibernate-core/src/main/java/org/hibernate/event/spi/EventType.java","lineNumber":92,"sourceCode":"\tpublic static final EventType<PostCollectionUpdateEventListener> POST_COLLECTION_UPDATE = create( \"post-collection-update\", PostCollectionUpdateEventListener.class );\n\n\t/**\n\t * Maintain a map of {@link EventType} instances keyed by name for lookup by name as well as {@link #values()}\n\t * resolution.\n\t */\n\tprivate static final Map<String,EventType<?>> STANDARD_TYPE_BY_NAME_MAP = initStandardTypeNameMap();\n\n\t@Nonnull\n\tprivate static Map<String, EventType<?>> initStandardTypeNameMap() {\n\t\tfinal Map<String, EventType<?>> typeByNameMap = new HashMap<>();\n\t\tfor ( Field field : EventType.class.getDeclaredFields() ) {\n\t\t\tif ( EventType.class.isAssignableFrom( field.getType() ) ) {\n\t\t\t\ttry {\n\t\t\t\t\tfinal EventType<?> typeField = (EventType<?>) field.get( null );\n\t\t\t\t\ttypeByNameMap.put( typeField.eventName(), typeField );\n\t\t\t\t}\n\t\t\t\tcatch ( Exception t ) {\n\t\t\t\t\tthrow new HibernateException( \"Unable to initialize EventType map\", t );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn Collections.unmodifiableMap( typeByNameMap );\n\t}\n\n\t@Nonnull\n\tprivate static <T> EventType<T> create(@Nonnull String name, @Nonnull Class<T> listenerRole) {\n\t\treturn new EventType<>( name, listenerRole, STANDARD_TYPE_COUNTER.getAndIncrement(), true );\n\t}\n\n\t@Nonnull\n\tpublic static <T> EventType<T> create(@Nonnull String name, @Nonnull Class<T> listenerRole, int ordinal) {\n\t\treturn new EventType<>( name, listenerRole, ordinal, false );\n\t}\n\n\t/**\n\t * Find an {@link EventType} by its name","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/spi/EventType.java#L74-L110","documentation":"HibernateException from EventType.initStandardTypeNameMap, the static initializer that reflectively scans EventType's own declared fields to build the standard name-to-EventType map; any reflective failure while reading a field (field.get(null) throwing) is wrapped and rethrown. Because this runs during EventType class initialization, failure breaks the entire Hibernate event system at first touch — effectively a broken-environment error, not an application-logic error.","triggerScenarios":"Field.get(null) failing during class init: mixed hibernate-core versions on the classpath (two jars' classes interleaved), a module system (JPMS) or security manager blocking reflective reads of the class's static fields, or bytecode processing (obfuscation, trimming, incomplete GraalVM native-image reflection metadata) removing or hiding the static EventType fields.","commonSituations":"Transitive dependencies pulling hibernate-core 5.x alongside 6.x; fat jars / shading that split org.hibernate classes across artifacts; native image builds without the official Hibernate GraalVM substitution/reflection config; aggressive R8/ProGuard rules renaming or stripping Hibernate internals.","solutions":["Verify exactly one hibernate-core version: mvn dependency:tree | grep hibernate-core (gradle dependencies --configuration runtimeClasspath) and add exclusions for the transitive duplicate","Rebuild the fat/shaded jar so all org.hibernate classes come from a single artifact; check for split packages","For GraalVM native images use Hibernate's official GraalVM support (org.hibernate.graalvm.Internal substitutions and reachability metadata) rather than hand-written reflection entries; relax obfuscation rules for org.hibernate.**"],"exampleFix":"# before (pom.xml, two versions pulled transitively)\n# hibernate-core:6.4.1.Final (direct) + hibernate-core:5.6.15.Final (via legacy dep)\n\n# after\n<dependency>\n  <groupId>legacy.lib</groupId>\n  <artifactId>legacy-lib</artifactId>\n  <exclusions>\n    <exclusion>\n      <groupId>org.hibernate</groupId>\n      <artifactId>hibernate-core</artifactId>\n    </exclusion>\n  </exclusions>\n</dependency>","handlingStrategy":"try-catch","validationCode":"// CI-time guard: fail the build when multiple hibernate-core versions are on the classpath\n// Maven: mvn dependency:tree -Dincludes=org.hibernate:hibernate-core\n// Maven Enforcer rule:\n//   <bannedDependencies><excludes><exclude>org.hibernate:hibernate-core</exclude></excludes></bannedDependencies>\n// plus a RequireUpperBoundDeps rule","typeGuard":"null","tryCatchPattern":"try {\n    sessionFactory = new Configuration().configure().buildSessionFactory();\n} catch (HibernateException e) {\n    if (\"Unable to initialize EventType map\".equals(e.getMessage())) {\n        throw new IllegalStateException(\n            \"Hibernate environment is broken (mixed hibernate-core versions, shading, or missing \" +\n            \"reflection config). Run: mvn dependency:tree | grep hibernate-core\", e);\n    }\n    throw e;\n}","preventionTips":["Pin a single hibernate-core version and exclude transitive copies (dependencyManagement + Enforcer)","For native images, use Hibernate's official GraalVM substitutions/reachability metadata","Keep obfuscators/trimmers from rewriting org.hibernate internals"],"tags":["hibernate","reflection","static-init","classpath","version-conflict","graalvm","jigsaw"],"backgroundTag":"classpath-version-conflict","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}