hibernate/hibernate-orm · error · IllegalArgumentException
Entity class may not be null
Error message
Entity class may not be null
What it means
Error "Entity class may not be null" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:2211
@Override
@Nullable
public <T> T find(
@Nonnull Class<T> entityClass,
@Nonnull Object primaryKey,
@Nonnull LockModeType lockModeType,
@Nullable Map<String, Object> properties) {
//noinspection ConstantValue
if ( lockModeType == null ) {
throw new IllegalArgumentException("Given LockModeType was null");
}
return doFind( entityClass, primaryKey, LockMode.fromJpaLockMode( lockModeType ), properties );
}
private <T> T doFind(Class<T> entityClass, Object primaryKey, LockMode lockMode, Map<String, Object> properties) {
checkOpen();
if ( entityClass == null ) {
throw new IllegalArgumentException( "Entity class may not be null" );
}
final var options = determineFindOptions( lockMode, properties );
final var entityDescriptor = requireEntityPersisterForLoad( entityClass );
return byKeyWithGraph( entityClass, entityDescriptor, properties, options )
.performFind( primaryKey );
}
private <T> FindByKeyOperation<T> byKeyWithGraph(
Class<T> entityClass,
EntityPersister entityDescriptor,
Map<String, Object> properties,
FindOption[] options) {
final var fetchHint = fetchGraphFromHints( properties );
final var loadHint = loadGraphFromHints( properties );
final GraphSemantic graphSemantic;
final RootGraphImplementor<?> graph;
if ( fetchHint != null ) {
if ( loadHint != null ) {View on GitHub (pinned to fad1729dce)
Solutions
- Supply the entity class explicitly (e.g. session.find(MyEntity.class, id)) rather than null.
- Verify the class object is not null before the call.
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java:2211 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/b9c3d0a122aeacba.
Report an issue: GitHub.