hibernate/hibernate-orm · error · TransientObjectException

Entity references an unsaved transient instance of '{}' (mak

Error message

Entity references an unsaved transient instance of '{}' (make the transient instance persistent before flushing)

What it means

Error "Entity references an unsaved transient instance of '{}' (make the transient instance persistent before flushing)" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/ForeignKeys.java:420

	public static Object getEntityIdentifier(
			final String entityName,
			final Object object,
			final SharedSessionContractImplementor session) {
		if ( object == null ) {
			return null;
		}
		else {
			final Object id = session.getContextEntityIdentifier( object );
			return id == null
					? session.getEntityPersister( entityName, object ).getIdentifier( object, session )
					: id;
		}
	}

	private static void throwIfTransient(String entityName, Object object, SharedSessionContractImplementor session) {
		if ( isTransient( entityName, object, Boolean.FALSE, session ) ) {
			throw new TransientObjectException( "Entity references an unsaved transient instance of '"
					+ (entityName == null ? session.guessEntityName(object) : entityName)
					+ "' (make the transient instance persistent before flushing)" );
		}
	}

	/**
	 * Find all non-nullable references to entities that have not yet
	 * been inserted in the database, where the foreign key
	 * is a reference to an unsaved transient entity. .
	 *
	 * @param entityName - the entity name
	 * @param entity - the entity instance
	 * @param values - insertable properties of the object (including backrefs),
	 * possibly with substitutions
	 * @param isEarlyInsert - true if the entity needs to be executed as soon as possible
	 * (e.g., to generate an ID)
	 * @param session - the session
	 *

View on GitHub (pinned to fad1729dce)

Solutions

  1. Persist the transient instance with session.persist() before flushing the referencing entity
  2. Add the appropriate cascade (e.g. PERSIST/ALL) on the association so the transient child is saved automatically

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/ForeignKeys.java:420 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/acd54d4e4ba50968. Report an issue: GitHub.