hibernate/hibernate-orm · error · SemanticException

'ESCAPE' may not be used with 'LIKE REGEXP'

Error message

'ESCAPE' may not be used with 'LIKE REGEXP'

What it means

Thrown by SemanticQueryBuilder.visitLikePredicate when an 'escape' clause is combined with 'like regexp'. Regular-expression matching does not use SQL escape characters, so the escape specification is meaningless there and is rejected with a SemanticException; the offending input is the like predicate carrying both clauses.

Solutions

  1. Remove the ESCAPE clause from the LIKE REGEXP predicate.
  2. Use a plain LIKE if escape handling is required.
Defensive patterns

Strategy: validation

When it happens

Trigger: A runtime precondition of the Hibernate API is violated.

Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:3266

				}
			}
			else {
				final var ordinalityColumnContext
						= (HqlParser.XmlTableOrdinalityColumnContext) columnContext;
				xmlTable.ordinalityColumn( visitIdentifier( ordinalityColumnContext.identifier() ) );
			}
		}
	}

	@Override
	public SqmPredicate visitLikePredicate(HqlParser.LikePredicateContext ctx) {
		final boolean negated = ctx.NOT() != null;
		final boolean caseSensitive = ctx.LIKE() != null;
		final var expression = (SqmExpression<?>) ctx.expression( 0 ).accept( this );
		final var pattern = (SqmExpression<?>) ctx.expression( 1 ).accept( this );
		if ( ctx.REGEXP() != null ) {
			if ( ctx.likeEscape() != null ) {
				throw new SemanticException( "'ESCAPE' may not be used with 'LIKE REGEXP'", query );
			}
			return new SqmBooleanExpressionPredicate(
					getFunctionDescriptor( "regexp_like" )
							.generateSqmExpression(
									caseSensitive
											? asList( expression, pattern )
											: asList( expression, pattern,
													new SqmLiteral<>( "i",
															nodeBuilder().getStringType(),
															nodeBuilder()
													)
											),
									null,
									queryEngine()
							),
					negated,
					nodeBuilder()
			);

View on GitHub (pinned to fad1729dce)