hibernate/hibernate-orm · critical · HibernateException

Unable to initialize EventType map

Error message

Unable to initialize EventType map

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/event/spi/EventType.java:92

	public static final EventType<PostCollectionUpdateEventListener> POST_COLLECTION_UPDATE = create( "post-collection-update", PostCollectionUpdateEventListener.class );

	/**
	 * Maintain a map of {@link EventType} instances keyed by name for lookup by name as well as {@link #values()}
	 * resolution.
	 */
	private static final Map<String,EventType<?>> STANDARD_TYPE_BY_NAME_MAP = initStandardTypeNameMap();

	@Nonnull
	private static Map<String, EventType<?>> initStandardTypeNameMap() {
		final Map<String, EventType<?>> typeByNameMap = new HashMap<>();
		for ( Field field : EventType.class.getDeclaredFields() ) {
			if ( EventType.class.isAssignableFrom( field.getType() ) ) {
				try {
					final EventType<?> typeField = (EventType<?>) field.get( null );
					typeByNameMap.put( typeField.eventName(), typeField );
				}
				catch ( Exception t ) {
					throw new HibernateException( "Unable to initialize EventType map", t );
				}
			}
		}
		return Collections.unmodifiableMap( typeByNameMap );
	}

	@Nonnull
	private static <T> EventType<T> create(@Nonnull String name, @Nonnull Class<T> listenerRole) {
		return new EventType<>( name, listenerRole, STANDARD_TYPE_COUNTER.getAndIncrement(), true );
	}

	@Nonnull
	public static <T> EventType<T> create(@Nonnull String name, @Nonnull Class<T> listenerRole, int ordinal) {
		return new EventType<>( name, listenerRole, ordinal, false );
	}

	/**
	 * Find an {@link EventType} by its name

View on GitHub (pinned to fad1729dce)

Solutions

  1. Verify exactly one hibernate-core version: mvn dependency:tree | grep hibernate-core (gradle dependencies --configuration runtimeClasspath) and add exclusions for the transitive duplicate
  2. Rebuild the fat/shaded jar so all org.hibernate classes come from a single artifact; check for split packages
  3. 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.**

Example fix

# before (pom.xml, two versions pulled transitively)
# hibernate-core:6.4.1.Final (direct) + hibernate-core:5.6.15.Final (via legacy dep)

# after
<dependency>
  <groupId>legacy.lib</groupId>
  <artifactId>legacy-lib</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>
Defensive patterns

Strategy: try-catch

Validate before calling

// CI-time guard: fail the build when multiple hibernate-core versions are on the classpath
// Maven: mvn dependency:tree -Dincludes=org.hibernate:hibernate-core
// Maven Enforcer rule:
//   <bannedDependencies><excludes><exclude>org.hibernate:hibernate-core</exclude></excludes></bannedDependencies>
// plus a RequireUpperBoundDeps rule

Type guard

null

Try / catch

try {
    sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException e) {
    if ("Unable to initialize EventType map".equals(e.getMessage())) {
        throw new IllegalStateException(
            "Hibernate environment is broken (mixed hibernate-core versions, shading, or missing " +
            "reflection config). Run: mvn dependency:tree | grep hibernate-core", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/a4053196cedbccd6. Report an issue: GitHub.