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

Error "'ESCAPE' may not be used with 'LIKE REGEXP'" thrown in hibernate/hibernate-orm.

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)

Solutions

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

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.