hibernate/hibernate-orm · error · IllegalArgumentException
Entity may not be null
Error message
Entity may not be null
What it means
Error "Entity may not be null" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:1625
uee.getMessage()
+ " ('" + entityClass.getSimpleName() + "' " + problem + ")",
e
);
}
}
}
}
// not for internal use:
@Override
@Nullable
public Object getIdentifier(@Nonnull Object object) {
checkOpen();
checkTransactionSyncStatus();
//noinspection ConstantValue
if ( object == null ) {
throw new IllegalArgumentException( "Entity may not be null" );
}
final var lazyInitializer = extractLazyInitializer( object );
if ( lazyInitializer != null ) {
checkOwnsProxy( lazyInitializer );
return lazyInitializer.getInternalIdentifier();
}
else {
return getEntityEntry( object ).getId();
}
}
/**
* Get the id value for an object that is actually associated with the session.
* This is a bit stricter than
* {@link org.hibernate.engine.internal.ForeignKeys#getEntityIdentifierIfNotUnsaved}.
*/
@Override
public Object getContextEntityIdentifier(@Nonnull Object object) {View on GitHub (pinned to fad1729dce)
Solutions
- Pass a non-null entity instance to the Session operation; null-check the object before calling persist/merge/remove/etc.
- If the entity may legitimately be absent, guard the call with an Optional or explicit if (entity != null).
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:1625 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/9b3ae3b9e89a72cb.
Report an issue: GitHub.