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/PersistEvent.java:30

 *
 * @author Gavin King
 *
 * @see org.hibernate.Session#persist
 */
public class PersistEvent extends AbstractSessionEvent {

	private Object object;
	private String entityName;

	public PersistEvent(@Nullable String entityName, @Nonnull Object original, @Nonnull EventSource source) {
		this(original, source);
		this.entityName = entityName;
	}

	public PersistEvent(@Nonnull Object object, @Nonnull EventSource source) {
		super(source);
		if ( object == null ) {
			throw new IllegalArgumentException( "Entity may not be null" );
		}
		this.object = object;
	}

	@Nonnull
	public Object getObject() {
		return object;
	}

	public void setObject(@Nonnull Object object) {
		this.object = object;
	}

	@Nullable
	public String getEntityName() {
		return entityName;
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Check the entity argument for null before calling persist().

When it happens

Trigger: Thrown when a caller passes a null Entity to the API guarded in PersistEvent.java:30.

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/52a93828acdccc13. Report an issue: GitHub.