From 82d5d07750b2556d8ad8f8aea6a123a1dae14f2d Mon Sep 17 00:00:00 2001 From: Hendrik Schreiber Date: Fri, 22 Sep 2023 17:09:11 +0200 Subject: [PATCH] HHH-17245 Better conform to SQLite/Xerial driver limitations. Added getAlterTableToAddUniqueKeyCommand(), which always returns "", because SQLite does not support unique constraints in ALTER TABLE statements (see here). Added getDefaultUseGetGeneratedKey(), which always returns false, as the Xerial driver does support GET_GENERATED_KEYS. --- .../community/dialect/SQLiteDialect.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 2916b91eb0..74013286f9 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 @@ -13,6 +13,7 @@ import java.util.Date; import java.util.TimeZone; import org.hibernate.ScrollMode; +import org.hibernate.boot.Metadata; import org.hibernate.boot.model.FunctionContributions; import org.hibernate.boot.model.TypeContributions; import org.hibernate.boot.model.relational.SqlStringGenerationContext; @@ -37,6 +38,7 @@ import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor; import org.hibernate.exception.spi.ViolatedConstraintNameExtractor; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.mapping.Column; +import org.hibernate.mapping.UniqueKey; import org.hibernate.query.SemanticException; import org.hibernate.query.sqm.IntervalType; import org.hibernate.dialect.NullOrdering; @@ -149,6 +151,19 @@ public class SQLiteDialect extends Dialect { public String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context) { return " unique"; } + + /** + * Alter table support in SQLite is very limited and does + * not include adding a unique constraint (as of 9/2023). + * + * @return always empty String + * @see SQLite SQL omissions + */ + @Override + public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context) { + return ""; + } + } @Override @@ -402,6 +417,16 @@ public class SQLiteDialect extends Dialect { return NullOrdering.SMALLEST; } + /** + * Generated keys are not supported by the (standard) Xerial driver (9/2022). + * + * @return false + */ + @Override + public boolean getDefaultUseGetGeneratedKeys() { + return false; + } + @Override public SqlAstTranslatorFactory getSqlAstTranslatorFactory() { return new StandardSqlAstTranslatorFactory() {