{"record":{"id":"bbfb9e70ba14092f","repo":"hibernate/hibernate-orm","slug":"mariadb-and-legacy-mysql-only-support-the-case-ins","errorCode":null,"errorMessage":"MariaDB and legacy MySQL only support the case insensitive flag 'i' as literal.","messagePattern":"MariaDB and legacy MySQL only support the case insensitive flag 'i' as literal\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/function/RegexpPredicateFunction.java","lineNumber":37,"sourceCode":" */\npublic class RegexpPredicateFunction extends AbstractRegexpLikeFunction {\n\n\tpublic RegexpPredicateFunction(TypeConfiguration typeConfiguration) {\n\t\tsuper( typeConfiguration );\n\t}\n\n\t@Override\n\tpublic void render(\n\t\t\tSqlAppender sqlAppender,\n\t\t\tList<? extends SqlAstNode> arguments,\n\t\t\tReturnableType<?> returnType,\n\t\t\tSqlAstTranslator<?> walker) {\n\t\tfinal boolean caseSensitive;\n\t\tif ( arguments.size() > 2 ) {\n\t\t\tif ( !(arguments.get( 2 ) instanceof Literal literal)\n\t\t\t\t|| !(literal.getLiteralValue() instanceof String flags)\n\t\t\t\t|| !flags.equals( \"i\" ) ) {\n\t\t\t\tthrow new IllegalArgumentException( \"MariaDB and legacy MySQL only support the case insensitive flag 'i' as literal.\" );\n\t\t\t}\n\t\t\tcaseSensitive = false;\n\t\t}\n\t\telse {\n\t\t\tcaseSensitive = true;\n\t\t}\n\n\t\tif ( !caseSensitive ) {\n\t\t\tsqlAppender.appendSql( \"lower(\" );\n\t\t}\n\t\targuments.get( 0 ).accept( walker );\n\t\tif ( !caseSensitive ) {\n\t\t\tsqlAppender.appendSql( ')' );\n\t\t}\n\t\tsqlAppender.appendSql( \" regexp \" );\n\t\tif ( caseSensitive ) {\n\t\t\tsqlAppender.appendSql( \"binary \" );\n\t\t}","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/RegexpPredicateFunction.java#L19-L55","documentation":"On MariaDB and legacy MySQL, Hibernate renders the regexp predicate with lower(...) wrapping for case-insensitivity. The flags argument must be the literal string 'i'; any other value or a non-literal flags expression throws IllegalArgumentException at rendering, because plain REGEXP/RLIKE on those databases exposes no flags.","triggerScenarios":"HQL: regexp_like(e.col, 'pat', 'g') or flags bound as a parameter/concatenation on MariaDB or legacy MySQL dialects.","commonSituations":"Test suites on MariaDB/MySQL rejecting HQL that works on Oracle or PostgreSQL; runtime-built flag strings; upgrading from Hibernate 5 regex handling to 6/7 dialect functions.","solutions":["Remove the flags argument when case sensitivity is fine","Pass exactly the literal 'i' when case-insensitive matching is needed","Move flag semantics into the pattern with inline modifiers like '(?i)'","Run the query as native SQL for advanced regex flags"],"exampleFix":"// before\nwhere regexp_like(e.code, :pattern, 'im')\n\n// after\nwhere regexp_like(e.code, '(?im)' || :pattern)   -- only 'i' is accepted as a flag literal","handlingStrategy":"validation","validationCode":"// MariaDB/legacy MySQL: only the literal 'i' is a valid regexp flag\nstatic String sanitizeMysqlFlags(String flags) {\n    if (flags == null || flags.isEmpty()) return null;\n    if (!\"i\".equals(flags)) {\n        throw new IllegalArgumentException(\"Only flag 'i' is supported, got: \" + flags);\n    }\n    return flags;\n}","typeGuard":null,"tryCatchPattern":"try {\n    return em.createQuery(hql).getResultList();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"case insensitive flag\")) {\n        return em.createQuery(lowercasedOperands(hql)).getResultList(); // lower() both operands\n    }\n    throw e;\n}","preventionTips":["Never parameterize regexp flags on MariaDB/MySQL","Keep flag handling per-dialect in a small helper instead of inline HQL","Test regex queries against every backend in the support matrix"],"tags":["hibernate","mariadb","mysql","regexp-like","sql-flags"],"backgroundTag":"regex-flags-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}