hibernate/hibernate-orm · error · FunctionArgumentException

Function () requires exactly 3 arguments when invoked with…

Error message

Function %s() requires exactly 3 arguments when invoked with a temporal argument, but %d arguments given

What it means

When start/stop are temporal (timestamp/time/date JDBC types), generate_series() has no implicit step: the validator demands a third argument (the step interval) and throws this FunctionArgumentException when only two arguments are given. Numeric series may omit the step, temporal series may not.

Solutions

  1. Add the explicit interval step: generate_series(:from, :to, by days(1)) / every(1, TimeUnit/jakarta TemporalUnit) per your Hibernate version's interval syntax
  2. Bind the step as a Duration/interval-typed parameter if dynamic
  3. For pure day ranges, generate a numeric series and add days in a select expression: generate_series(0, daysBetween, 1) combined with :from + gs days

Example fix

// before
List<LocalDateTime> ds = session.createQuery(
    "select gs from generate_series(:f, :t) gs", LocalDateTime.class)...;

// after
List<LocalDateTime> ds = session.createQuery(
    "select gs from generate_series(:f, :t, by minutes(30)) gs", LocalDateTime.class)...;
Defensive patterns

Strategy: validation

Validate before calling

if (isTemporal(start) && step == null) {
    throw new IllegalArgumentException("Temporal generate_series needs an explicit step interval");
}
// then always build: generate_series(:f, :t, by minutes(N))

Type guard

boolean isTemporalSeries(Object start) {
    return start instanceof java.time.temporal.Temporal;
}

Prevention

When it happens

Trigger: HQL 'from generate_series(:from, :to)' where both parameters are LocalDateTime/OffsetDateTime/Date, with no third interval argument; ported PostgreSQL SQL generate_series(ts1, ts2) relying on a default 1-day step, which the emulation does not define.

Common situations: Day-range generators (one row per day) written without explicit interval '1 day'; migrating raw SQL to HQL; refactors that dropped the step argument by mistake.

Related errors


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/GenerateSeriesArgumentValidator.java:86

				if ( stepType == null ) {
					throw unknownType( functionName, arguments, 2 );
				}
				if ( stepType != startType ) {
					throw new FunctionArgumentException(
							String.format(
									"Step parameter of function '%s()' is of type '%s', but must be of the same type as start and stop [%s,%s]",
									functionName,
									stepType.getTypeName(),
									startType.getTypeName(),
									stopType.getTypeName()
							)
					);
				}
			}
		}
		else if ( jdbcType.isTemporal() ) {
			if ( step == null ) {
				throw new FunctionArgumentException(
						String.format(
								Locale.ROOT,
								"Function %s() requires exactly 3 arguments when invoked with a temporal argument, but %d arguments given",
								functionName,
								arguments.size()
						)
				);
			}
			if ( stepType == null ) {
				throw unknownType( functionName, arguments, 2 );
			}
			final var stepJdbcType = ((JdbcMapping) stepType).getJdbcType();
			if ( !stepJdbcType.isInterval() && !stepJdbcType.isDuration() ) {
				throw new FunctionArgumentException(
						String.format(
								"Step parameter of function '%s()' is of type '%s', but must be of type interval",
								functionName,
								stepType.getTypeName()

View on GitHub (pinned to fad1729dce)