hibernate/hibernate-orm · error · AssertionFailure

force initializing collection loading

Error message

force initializing collection loading

What it means

forceInitialization fully loads a collection (used by cascading actions and lazy-state handling). If the collection is already mid-initialization, re-entering initialize would recurse, so Hibernate throws AssertionFailure. This is a reentrancy problem: loading collection A triggers, through listeners, bidirectional cascades, or eager cycles, a force-initialization of A itself.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/collection/spi/AbstractPersistentCollection.java:847

		// the param would have to be bound twice.  Until we eventually add "parameter bind points" concepts to the
		// AST in ORM 5+, handling this type of condition is either extremely difficult or impossible.  Forcing
		// recreation isn't ideal, but not really any other option in ORM 4.
		// Selecting a type used in where part of update statement
		// (must match condition in org.hibernate.persister.collection.BasicCollectionPersister#doUpdateRows).
		// See HHH-9474
		final Type whereType =
				persister.hasIndex()
						? persister.getIndexType()
						: persister.getElementType();
		return whereType instanceof CompositeType compositeType
			&& compositeType.hasNullProperty();
	}

	@Override
	public final void forceInitialization() throws HibernateException {
		if ( !initialized ) {
			if ( initializing ) {
				throw new AssertionFailure( "force initializing collection loading" );
			}
			initialize( false );
		}
	}


	/**
	 * Get the current snapshot from the session
	 */
	protected final Serializable getSnapshot() {
		return session.getPersistenceContext().getSnapshot( this );
	}

	@Override
	public final boolean wasInitialized() {
		return initialized;
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Break the cycle: make one side of the bidirectional association lazy and drop mapping-level eager fetch
  2. Remove collection initialization from load-time event listeners and interceptors
  3. Prefer query-level join fetch over mapping-level eager fetching for the paths that need data
  4. Reproduce with a minimal mapping and check/report on the Hibernate JIRA - AssertionFailure marks an internal invariant break

Example fix

// before: eager on both sides of a bidirectional relation
@OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
List<Child> children;
@ManyToOne(fetch = FetchType.EAGER) Parent parent;

// after
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
List<Child> children; // fetch explicitly with 'join fetch' where needed
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Event listeners or interceptors that initialize collections during onLoad/onLoadCollection; bidirectional relations eager-fetched on both sides forming a cycle; bytecode enhancement interacting with custom loaders; rare internal bugs in specific versions.

Common situations: Custom load-time listeners touching associations; circular fetch-join graphs; behavior changes after a Hibernate upgrade.

Related errors


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