hibernate/hibernate-orm · error · HibernateException

return class is required

Error message

return class is required

What it means

Error "return class is required" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/id/enhanced/AbstractOptimizer.java:26

/**
 * Common support for {@link Optimizer} implementations.
 *
 * @author Steve Ebersole
 */
public abstract class AbstractOptimizer implements Optimizer {
	protected final Class<?> returnClass;
	protected final int incrementSize;

	/**
	 * Construct an optimizer
	 *
	 * @param returnClass The expected id class.
	 * @param incrementSize The increment size
	 */
	AbstractOptimizer(Class<?> returnClass, int incrementSize) {
		if ( returnClass == null ) {
			throw new HibernateException( "return class is required" );
		}
		this.returnClass = returnClass;
		this.incrementSize = incrementSize;
	}

	/**
	 * Getter for property 'returnClass'.  This is the Java
	 * class which is used to represent the id (e.g. {@link Long}).
	 *
	 * @return Value for property 'returnClass'.
	 */
	public final Class<?> getReturnClass() {
		return returnClass;
	}

	@Override
	public final int getIncrementSize() {
		return incrementSize;

View on GitHub (pinned to fad1729dce)

Solutions

  1. Specify the id property type (return class) for the optimizer-backed generator in the mapping.

When it happens

Trigger: Thrown when an identifier generator produces or is asked for a Java type it does not support.

Common situations: Typical situations: mapping a numeric id to an unsupported type; a UUID generator configured with a non-UUID return type.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/0184fea00410fb48. Report an issue: GitHub.