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/engine/internal/StatefulPersistenceContext.java:1694
nullAssociations = setOfSize( INIT_COLL_SIZE );
}
nullAssociations.add( new AssociationKey( ownerKey, propertyName ) );
}
@Override
public boolean isPropertyNull(EntityKey ownerKey, String propertyName) {
return nullAssociations != null
&& nullAssociations.contains( new AssociationKey( ownerKey, propertyName ) );
}
private void clearNullProperties() {
nullAssociations = null;
}
@Override
public boolean isReadOnly(Object entityOrProxy) {
if ( entityOrProxy == null ) {
throw new IllegalArgumentException( "Entity may not be null" );
}
final var lazyInitializer = extractLazyInitializer( entityOrProxy );
if ( lazyInitializer != null ) {
return lazyInitializer.isReadOnly();
}
else {
final var ee = getEntry( entityOrProxy );
if ( ee == null ) {
throw new UnmanagedObjectException( "Given entity is not associated with the persistence context" );
}
return ee.isReadOnly();
}
}
@Override
public void setReadOnly(Object object, boolean readOnly) {
if ( object == null ) {View on GitHub (pinned to fad1729dce)
Solutions
- Pass a non-null entity instance to the persistence-context operation
- Guard against null before calling getEntry/removeEntity on the persistence context
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java:1694 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/ce8e90d77cf9a857.
Report an issue: GitHub.