hibernate/hibernate-orm · error · ObjectDeletedException

attempted to lock a deleted instance

Error message

attempted to lock a deleted instance

What it means

Error "attempted to lock a deleted instance" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderHelper.java:69

	 * requested mode, performing a pessimistic lock upgrade on a given entity, if needed.
	 *
	 * @param object The entity for which to upgrade the lock.
	 * @param entry The entity's {@link EntityEntry} instance.
	 * @param lockOptions Contains the requested lock mode.
	 * @param session The session which is the source of the event being processed.
	 */
	public static void upgradeLock(
			@Nonnull Object object,
			@Nonnull EntityEntry entry,
			@Nonnull LockOptions lockOptions,
			@Nonnull SharedSessionContractImplementor session) {
		final var requestedLockMode = lockOptions.getLockMode();
		if ( requestedLockMode.greaterThan( entry.getLockMode() ) ) {
			// Request is for a more restrictive lock than the lock already held
			final var persister = entry.getPersister();

			if ( entry.getStatus().isDeletedOrGone()) {
				throw new ObjectDeletedException(
						"attempted to lock a deleted instance",
						entry.getId(),
						persister.getEntityName()
				);
			}

			if ( LOADER_LOGGER.isTraceEnabled() ) {
				LOADER_LOGGER.tracef(
						"Locking %s with id '%s' in mode %s",
						persister.getEntityName(),
						entry.getId(),
						requestedLockMode
				);
			}

			CacheLock cacheLock = null;
			try {
				final EntityEntry entryToLock = entry;

View on GitHub (pinned to fad1729dce)

Solutions

  1. Do not lock entities scheduled for deletion; check the entity state before locking.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderHelper.java:69 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/cb824cdac24af8f3. Report an issue: GitHub.