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/event/spi/LockEvent.java:32
/**
* Event class for {@link org.hibernate.Session#lock}.
*
* @author Steve Ebersole
*
* @see org.hibernate.Session#lock
*/
public class LockEvent extends AbstractSessionEvent {
public static final String ILLEGAL_SKIP_LOCKED = "Skip-locked is not valid option for #lock";
private Object object;
private final LockOptions lockOptions;
private String entityName;
public LockEvent(@Nullable String entityName, @Nonnull Object object, @Nonnull LockOptions lockOptions, @Nonnull EventSource source) {
super(source);
if (object == null) {
throw new IllegalArgumentException( "Entity may not be null" );
}
if (lockOptions == null) {
throw new IllegalArgumentException( "LockOptions may not be null" );
}
if ( lockOptions.getLockMode() == LockMode.UPGRADE_SKIPLOCKED
|| lockOptions.getTimeout().milliseconds() == Timeouts.SKIP_LOCKED_MILLI ) {
throw new IllegalArgumentException( ILLEGAL_SKIP_LOCKED );
}
this.entityName = entityName;
this.object = object;
this.lockOptions = lockOptions;
}
public LockEvent(@Nonnull Object object, @Nonnull LockOptions lockOptions, @Nonnull EventSource source) {
this( null, object, lockOptions, source );
}
View on GitHub (pinned to fad1729dce)
Solutions
- Check the entity argument for null before calling lock().
When it happens
Trigger: Thrown when a caller passes a null Entity to the API guarded in LockEvent.java:32.
Common situations: Typical situations: calling the method with an uninitialized variable; a lookup that returned null being passed straight through; missing null-checks in application code before invoking Hibernate.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/2035b013841217d3.
Report an issue: GitHub.