hibernate/hibernate-orm · error · UnsupportedOperationException

format() function not supported on Sybase

Error message

format() function not supported on Sybase

What it means

SybaseDialect.appendDatetimeFormat() throws UnsupportedOperationException('format() function not supported on Sybase') because SAP ASE/JConnect has no portable format() equivalent for datetime-to-string formatting with a pattern. In Hibernate 6, every HQL `format(datetime, pattern)` call (and functions that render a datetime format, like certain str()/to_char translations) funnels into this method; on Sybase the dialect deliberately fails rather than emitting wrong SQL.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/dialect/SybaseDialect.java:522

	public boolean supportsFractionalTimestampArithmetic() {
		return false;
	}

	@Override @SuppressWarnings("deprecation")
	public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType, IntervalType intervalType) {
		//TODO!!
		return "dateadd(?1,?2,?3)";
	}

	@Override @SuppressWarnings("deprecation")
	public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalType, TemporalType toTemporalType) {
		//TODO!!
		return "datediff(?1,?2,?3)";
	}

	@Override
	public void appendDatetimeFormat(SqlAppender appender, String format) {
		throw new UnsupportedOperationException( "format() function not supported on Sybase");
	}

	@Override
	public boolean supportsStandardCurrentTimestampFunction() {
		return false;
	}

	@Override
	public IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData metadata)
			throws SQLException {
		// Default to MIXED because the jconnect driver doesn't seem to report anything useful
		builder.setUnquotedCaseStrategy( IdentifierCaseStrategy.MIXED );
		if ( metadata == null ) {
			builder.setQuotedCaseStrategy( IdentifierCaseStrategy.MIXED );
		}

		return super.buildIdentifierHelper( builder, metadata );
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Format dates in application code: select the raw timestamp and format with java.time.format.DateTimeFormatter.
  2. Register a dialect function for Sybase's strftime-style equivalent if your ASE version has one (e.g. via a custom FunctionContributor implementing appendDatetimeFormat with 'strfmt' and subclassing SybaseDialect).
  3. Use native SQL queries with ASE's convert(varchar, col, style) for the required shapes.
  4. Avoid format()/to_char-style HQL in shared repository code, or branch it out for Sybase profiles.

Example fix

// before (HQL, works on PG/MySQL, throws on Sybase)
select format(e.createdAt, 'yyyy-MM-dd') from Event e

// after — fetch raw and format in Java
select e.createdAt from Event e
// then: createdAt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
Defensive patterns

Strategy: fallback

Validate before calling

static boolean supportsDatetimeFormat(Dialect d) { return !(d instanceof SybaseDialect); }
// build HQL with format() only when supportsDatetimeFormat(dialect); otherwise select raw temporal and format in Java

Try / catch

try {
  return em.createQuery(hqlWithFormat).getResultList();
} catch (UnsupportedOperationException e) {
  if (e.getMessage().contains("format() function not supported on Sybase")) {
    List<Timestamp> raw = em.createQuery(hqlRaw, Timestamp.class).getResultList();
    return raw.stream().map(t -> t.toLocalDateTime().format(FMT)).toList();
  }
  throw e;
}

Prevention

When it happens

Trigger: Executing HQL that uses `format(e.timestamp, 'yyyy-MM-dd')` (or JPQL/Criteria equivalents that map onto appendDatetimeFormat) against a Sybase ASE datasource using SybaseDialect; also `str(...)` style datetime formatting in HQL that resolves to the datetime-format path.

Common situations: Applications developed on PostgreSQL/MySQL (to_char/date_format) migrated to Sybase ASE; reporting queries that format dates in the database; shared query libraries where formatting works on most dialects but explodes on the Sybase profile.

Related errors


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