hibernate/hibernate-orm · error · TransientObjectException

Object passed to upsert() has an unsaved identifier value: "

Error message

Object passed to upsert() has an unsaved identifier value: " + persister.getEntityName()

What it means

Error "Object passed to upsert() has an unsaved identifier value: " + persister.getEntityName()" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:859

			}
		}
		else {
			return null;
		}
	}

	// Hibernate Reactive calls this
	protected Object idToUpsert(Object entity, EntityPersister persister) {
		final Object id = persister.getIdentifier( entity, this );
		if ( id == null ) {
			throw new IllegalArgumentException( "Object passed to upsert() has no identifier" );
		}
		final Boolean unsaved =
				persister.getIdentifierMapping()
						.getUnsavedStrategy()
						.isUnsaved( id );
		if ( unsaved != null && unsaved ) {
			throw new TransientObjectException( "Object passed to upsert() has an unsaved identifier value: "
					+ persister.getEntityName() );
		}
		return id;
	}

	// event processing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	// Hibernate Reactive may need to call this
	protected boolean firePreInsert(Object entity, Object id, Object[] state, EntityPersister persister) {
		final var callbacks = persister.getEntityCallbacks();
		final boolean hasPrePersistCallbacks = callbacks.hasRegisteredCallbacks( CallbackType.PRE_PERSIST );
		final boolean hasPreInsertCallbacks = callbacks.hasRegisteredCallbacks( CallbackType.PRE_INSERT );
		if ( ( hasPrePersistCallbacks || hasPreInsertCallbacks )
				&& callEntityLifecycleCallback( () -> {
					final boolean prePersist = hasPrePersistCallbacks && callbacks.preCreate( entity );
					return hasPreInsertCallbacks && callbacks.preInsert( entity ) || prePersist;
				} ) ) {
			copyStateFromEntity( entity, state, persister );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Assign a proper saved identifier value before upsert(); the current id matches the entity's unsaved-value marker, so Hibernate treats it as transient.
  2. Adjust the unsaved-value configuration or persist the entity first.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:859 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/82218640f2381b1c. Report an issue: GitHub.