hibernate/hibernate-orm · info · UnsupportedOperationException

Unsupported specification: {specification}

Error message

Unsupported specification: {specification}

What it means

SQLServerLegacyDialect.trimPattern() renders trim patterns for SQL Server 2022+ (dialect version >= 16, which added trim/ltrim/rtrim with a characters argument). The switch covers all three TrimSpec constants (BOTH, LEADING, TRAILING), so the 'Unsupported specification' throw is a defensive dead branch: it can only fire if the TrimSpec enum ever gains a new constant or a subclass invokes trimPattern with an out-of-enum value. It is not reachable through the public HQL/Criteria API today.

Source

Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLServerLegacyDialect.java:561

	@Override
	public String trimPattern(TrimSpec specification, boolean isWhitespace) {
		if ( getVersion().isSameOrAfter( 16 ) ) {
			switch ( specification ) {
				case BOTH:
					return isWhitespace
							? "trim(?1)"
							: "trim(?2 from ?1)";
				case LEADING:
					return isWhitespace
							? "ltrim(?1)"
							: "ltrim(?1,?2)";
				case TRAILING:
					return isWhitespace
							? "rtrim(?1)"
							: "rtrim(?1,?2)";
			}
			throw new UnsupportedOperationException( "Unsupported specification: " + specification );
		}
		return super.trimPattern( specification, isWhitespace );
	}

	@Override
	public SqlAstTranslatorFactory getSqlAstTranslatorFactory() {
		return new StandardSqlAstTranslatorFactory() {
			@Override
			protected <T extends JdbcOperation> SqlAstTranslator<T> buildTranslator(
					SessionFactoryImplementor sessionFactory, Statement statement) {
				return new SQLServerLegacySqlAstTranslator<>( sessionFactory, statement );
			}
		};
	}

	@Override
	public AggregateSupport getAggregateSupport() {
		return SQLServerAggregateSupport.valueOf( this );

View on GitHub (pinned to fad1729dce)

Solutions

  1. No application change needed; if it ever appears, align the hibernate-community-dialects version with the hibernate-orm version
  2. Keep HQL trim usage to leading/trailing/both specifications
  3. Report it as a dialect bug in the Hibernate tracker if genuinely reached
Defensive patterns

Strategy: validation

Validate before calling

if ( specification == TrimSpec.LEADING
        || specification == TrimSpec.TRAILING
        || specification == TrimSpec.BOTH ) {
    // safe: SQLServerLegacyDialect.trimPattern handles all three on 2022+
    String pattern = dialect.trimPattern( specification, isWhitespace );
}

Prevention

When it happens

Trigger: Not reachable from application code with current Hibernate versions: HQL trim()/ltrim()/rtrim() with leading/trailing/both all map to handled cases. Would only surface after a future Hibernate version adds a new TrimSpec constant while running against a stale hibernate-community-dialects build.

Common situations: Version skew between hibernate-orm and hibernate-community-dialects after a partial upgrade.

Related errors


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