From 4c7445f6aa4e055539b4c7c39cb52ee06e973b04 Mon Sep 17 00:00:00 2001 From: gwenn <45554+gwenn@users.noreply.github.com> Date: Sat, 10 May 2025 07:59:29 +0200 Subject: [PATCH] HHH-19444 SQLiteDialect - Fix ViolatedConstraintNameExtractor See https://github.com/sqlite/sqlite/commit/f9c8ce3ced8960e7c8d74b68ad420ec5f581494d > Standardize the error messages generated by constraint failures to a format of "$TYPE constraint failed: $DETAIL". Also in case [extended result codes](http://sqlite.org/c3ref/extended_result_codes.html) are activated, we need the `& 0xFF`. And as there seems to be no way to tell `extractUsingTemplate` that there is no `templateEnd`, the linefeed is used... See [original](https://github.com/gwenn/sqlite-dialect/blob/c87223460e3335ff4f041e012bd0d22df99fa2af/src/main/java/org/sqlite/hibernate/dialect/SQLiteDialect.java#L244-L253) code and associated [test](https://github.com/gwenn/sqlite-dialect/blob/c87223460e3335ff4f041e012bd0d22df99fa2af/src/test/java/org/hibernate/tutorial/annotations/AnnotationsIllustrationTest.java#L95-L105) for reference. --- .../java/org/hibernate/community/dialect/SQLiteDialect.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java index 07dc510bb885..67c565bf73c2 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SQLiteDialect.java @@ -457,9 +457,9 @@ public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() { private static final ViolatedConstraintNameExtractor EXTRACTOR = new TemplatedViolatedConstraintNameExtractor( sqle -> { - final int errorCode = JdbcExceptionHelper.extractErrorCode( sqle ); + final int errorCode = JdbcExceptionHelper.extractErrorCode( sqle ) & 0xFF; if (errorCode == SQLITE_CONSTRAINT) { - return extractUsingTemplate( "constraint ", " failed", sqle.getMessage() ); + return extractUsingTemplate( "constraint failed: ", "\n", sqle.getMessage() ); } return null; } );