hibernate/hibernate-orm · error · SemanticException

Unrecognized field: ${unit}

Error message

Unrecognized field: ${unit}

What it means

Error "Unrecognized field: ${unit}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java:557

			// instead of an INTERVAL
			return switch (unit) {
				case YEAR, MONTH, QUARTER -> "extract(" + translateDurationField( unit ) + " from age(?3,?2))";
				default -> "(?3-?2)" + DAY.conversionFactor( unit, this );
			};
		}
		else {
			return switch (unit) {
				case YEAR -> "extract(year from ?3-?2)";
				case QUARTER -> "(extract(year from ?3-?2)*4+extract(month from ?3-?2)/3)";
				case MONTH -> "(extract(year from ?3-?2)*12+extract(month from ?3-?2))";
				case WEEK -> "(extract(day from ?3-?2)/7)"; // week is not supported by extract() when the argument is a duration
				case DAY -> "extract(day from ?3-?2)";
				// in order to avoid multiple calls to extract(),
				// we use extract(epoch from x - y) * factor for
				// all the following units:
				case HOUR, MINUTE, SECOND, NANOSECOND, NATIVE ->
						"extract(epoch from ?3-?2)" + EPOCH.conversionFactor( unit, this );
				default -> throw new SemanticException( "Unrecognized field: " + unit );
			};
		}
	}

	@Override
	public TimeZoneSupport getTimeZoneSupport() {
		return TimeZoneSupport.NORMALIZE;
	}

	@Override
	public void initializeFunctionRegistry(FunctionContributions functionContributions) {
		super.initializeFunctionRegistry( functionContributions );

		final var functionFactory = new CommonFunctionFactory( functionContributions );

		functionFactory.cot();
		functionFactory.radians();
		functionFactory.degrees();

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use a recognized temporal field name.
  2. Verify the unit passed to the function.

When it happens

Trigger: Triggered when the application calls a Hibernate dialect feature that the configured database dialect cannot provide: Unrecognized field: $the given unit.

Common situations: Common when running against a database whose dialect lacks this capability, when a mapping or HQL/Criteria query requests unsupported functionality, or when the wrong dialect is configured for the database in use. Error: Unrecognized field: $the given unit.


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