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
- No application change needed; if it ever appears, align the hibernate-community-dialects version with the hibernate-orm version
- Keep HQL trim usage to leading/trailing/both specifications
- 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
- Keep hibernate-community-dialects and hibernate-orm versions in lockstep
- Call dialect.trimPattern() only with the three standard TrimSpec values
- Treat this exception as a version-skew signal if it ever appears
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
- Insert conflict 'do update' clause with constraint name is n
- Can't emulate offset clause in subquery
- Unsupported specification: {specification}
- Newer version [" + latestVersion + "] of entity [" + infoStr
- unsaved-value NEGATIVE may only be used with short, int and
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/c32c29da3a2a4fde.
Report an issue: GitHub.