hibernate/hibernate-orm · error · HibernateException

Collection '${role}' was not processed by flush (this is lik

Error message

Collection '${role}' was not processed by flush (this is likely due to unsafe use of the session, for example, current use in multiple threads, or updates during entity lifecycle callbacks)

What it means

Error "Collection '${role}' was not processed by flush (this is likely due to unsafe use of the session, for example, current use in multiple threads, or updates during entity lifecycle callbacks)" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java:209

	}

	public void postInitialize(PersistentCollection<?> collection, SharedSessionContractImplementor session) {
		final var loadedPersister = this.loadedPersister;
		snapshot = loadedPersister != null && isModifiable() ? collection.getSnapshot( loadedPersister ) : null;
		collection.setSnapshot( loadedKey, role, snapshot );
		if ( loadedPersister != null
				&& session.getLoadQueryInfluencers().effectivelyBatchLoadable( loadedPersister ) ) {
			session.getPersistenceContextInternal().getBatchFetchQueue()
					.removeBatchLoadableCollection( this );
		}
	}

	/**
	 * Called after a successful flush
	 */
	public void postFlush(PersistentCollection<?> collection, CollectionFlushActionTracker collectionFlushActionTracker) {
		if ( !ignore && !collectionFlushActionTracker.wasCollectionProcessed( collection ) ) {
			throw new HibernateException( "Collection '" + collection.getRole() + "' was not processed by flush"
					+ " (this is likely due to unsafe use of the session, for example, current use in multiple threads, or updates during entity lifecycle callbacks)");
		}
		ignore = false;
		collection.setSnapshot( loadedKey, role, snapshot );
	}

	/**
	 * Called after execution of an action
	 */
	public void afterAction(PersistentCollection<?> collection) {
		loadedKey = currentKey;
		loadedPersister = currentPersister;
		role = currentPersister == null ? null : currentPersister.getRole();
		if ( collection.wasInitialized()
				&& hasQueuedCollectionAction( collection ) ) {
			// update the snapshot
			snapshot = isModifiable()
					? collection.getSnapshot( castNonNull( loadedPersister ) )

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use the session from a single thread only and avoid concurrent access
  2. Do not modify entities inside lifecycle callbacks in ways that bypass flush processing
  3. Ensure flush completes before the collection is accessed again

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java:209 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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