Class KeycloakSQLServerDialect

java.lang.Object
org.hibernate.dialect.Dialect
org.hibernate.dialect.AbstractTransactSQLDialect
org.hibernate.dialect.SQLServerDialect
org.keycloak.connections.jpa.dialect.KeycloakSQLServerDialect
All Implemented Interfaces:
org.hibernate.boot.model.FunctionContributor, org.hibernate.boot.model.TypeContributor, org.hibernate.exception.spi.ConversionContext

public class KeycloakSQLServerDialect extends org.hibernate.dialect.SQLServerDialect
Fixes Hibernate's SQL Server dialect to correctly handle HQL insert ... on conflict ... do nothing by emitting a MERGE statement instead of a plain INSERT that silently drops the conflict clause.

The MERGE target gets a HOLDLOCK hint for all conflict clauses. Without it, two concurrent upserts of the same new key can both take the "not matched" branch, and one fails with a unique constraint violation.

See HHH-20826 for the upstream tracker.

  • Nested Class Summary

    Nested classes/interfaces inherited from class org.hibernate.dialect.Dialect

    org.hibernate.dialect.Dialect.SizeStrategy, org.hibernate.dialect.Dialect.SizeStrategyImpl
  • Field Summary

    Fields inherited from class org.hibernate.dialect.Dialect

    CLOSED_QUOTE, FALSE_STRING_VALUES, LEGACY_LOB_MERGE_STRATEGY, LOG_BASE2OF10, NEW_LOCATOR_LOB_MERGE_STRATEGY, QUOTE, STANDARD_MULTI_KEY_LOAD_SIZING_STRATEGY, STREAM_XFER_LOB_MERGE_STRATEGY, TRUE_STRING_VALUES
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    KeycloakSQLServerDialect(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo info)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.hibernate.sql.ast.SqlAstTranslatorFactory
     

    Methods inherited from class org.hibernate.dialect.SQLServerDialect

    addPartitionKeyToPrimaryKey, appendCheckConstraintOptions, appendDatetimeFormat, appendDateTimeLiteral, appendDateTimeLiteral, appendDateTimeLiteral, appendLockHint, appendUUIDLiteral, buildIdentifierHelper, buildSQLExceptionConversionDelegate, castPattern, castType, closeQuote, columnType, contributeTypes, createOptionalTableUpdateOperation, currentDate, currentTime, currentTimestamp, currentTimestampWithTimeZone, datetimeFormat, determineDatabaseVersion, doesReadCommittedCauseWritersToBlockReaders, doesRepeatableReadCauseReadersToBlockWriters, extractPattern, generatedAs, getAggregateSupport, getAlterColumnTypeString, getCallableStatementSupport, getCheckConstraintString, getCreateIndexString, getCreateIndexTail, getCreateTemporaryTableColumnAnnotation, getCurrentSchemaCommand, getCurrentTimestampSelectString, getDefaultLobLength, getDefaultTimestampPrecision, getDmlTargetColumnQualifierSupport, getDropSchemaCommand, getFractionalSecondPrecisionInNanos, getIdentityColumnSupport, getInExpressionCountLimit, getLimitHandler, getLocalTemporaryTableStrategy, getLockingSupport, getMaxIdentifierLength, getMaximumSeriesSize, getMaxNVarcharLength, getMaxTimestampPrecision, getMaxVarcharLength, getMinimumSupportedVersion, getNameQualifierSupport, getNoColumnsInsertString, getPreferredSqlTypeCodeForArray, getQueryHintString, getQuerySequencesString, getSequenceExporter, getSequenceSupport, getSizeStrategy, getTableExporter, getTemporalTableSupport, getTimeZoneSupport, getUniqueDelegate, getViolatedConstraintNameExtractor, hasDataTypeBeforeGeneratedAs, initializeFunctionRegistry, openQuote, registerColumnTypes, registerDefaultKeywords, resolveSqlTypeDescriptor, roundsToMaxPrecisionFirst, supportsAlterColumnType, supportsBindingNullForSetObject, supportsCircularCascadeDeleteConstraints, supportsDistinctFromPredicate, supportsFetchClause, supportsFromClauseInUpdate, supportsIfExistsBeforeConstraintName, supportsIfExistsBeforeIndexName, supportsIfExistsBeforeTableName, supportsJoinsInDelete, supportsLateral, supportsLobValueChangePropagation, supportsNonQueryWithCTE, supportsNullPrecedence, supportsOffsetInSubquery, supportsRecursiveCTE, supportsResultSetPositionQueryMethodsOnForwardOnlyCursor, supportsRowValueConstructorSyntax, supportsRowValueConstructorSyntaxInInList, supportsRowValueConstructorSyntaxInQuantifiedPredicates, supportsSimpleQueryGrouping, supportsValuesList, supportsWindowFunctions, supportsWithClauseInSubquery, timestampaddPattern, timestampdiffPattern, translateDurationField, translateExtractField, trimPattern

    Methods inherited from class org.hibernate.dialect.AbstractTransactSQLDialect

    appendBinaryLiteral, applyLocksToSql, getAddColumnString, getDefaultStatementBatchSize, getFallbackSqmInsertStrategy, getFallbackSqmMutationStrategy, getForUpdateString, getLockingClauseStrategy, getNullOrdering, getPreferredSqlTypeCodeForBoolean, getResultSet, getSelectGUIDString, getSupportedTemporaryTableKind, getTemporaryTableAfterUseAction, getTemporaryTableBeforeUseAction, getTemporaryTableCreateCommand, isCurrentTimestampSelectStringCallable, qualifyIndexName, registerResultSetOutParameter, replaceLtrimRtrim, requiresCastForConcatenatingNonStrings, supportsCurrentTimestampSelection, supportsExistsInSelect, supportsPartitionBy, supportsTupleDistinctCounts

    Methods inherited from class org.hibernate.dialect.Dialect

    addSqlHintOrComment, addUseIndexQueryHint, appendArrayLiteral, appendBooleanValueString, appendIntervalLiteral, appendIntervalLiteral, appendLiteral, augmentPhysicalTableTypes, augmentRecognizedTableTypes, buildLockingClauseStrategy, buildOptimisticForceIncrementStrategy, buildOptimisticStrategy, buildPessimisticForceIncrementStrategy, buildPessimisticReadStrategy, buildPessimisticWriteStrategy, buildReadStrategy, buildStringToBooleanCast, buildStringToBooleanCastDecode, buildStringToBooleanDecode, canBatchTruncate, canCreateCatalog, canCreateSchema, canDisableConstraints, causesRollback, checkVersion, contribute, contributeFunctions, currentLocalTime, currentLocalTimestamp, defaultScrollMode, doesRoundTemporalOnOverflow, dropConstraints, equivalentTypes, escapeComment, forceLobAsLastValue, getAddColumnSuffixString, getAddForeignKeyConstraintString, getAddForeignKeyConstraintString, getAddPrimaryKeyConstraintString, getAlterTableString, getArrayTypeName, getAuxiliaryDatabaseObjectExporter, getBatchLoadSizingStrategy, getBeforeDropStatement, getCascadeConstraintsString, getCaseInsensitiveLike, getCatalogSeparator, getCheckCondition, getCheckCondition, getCheckCondition, getCheckCondition, getCheckCondition, getCheckCondition, getColumnAliasExtractor, getColumnComment, getColumnDefaultString, getCreateCatalogCommand, getCreateEnumTypeCommand, getCreateEnumTypeCommand, getCreateMultisetTableString, getCreateSchemaCommand, getCreateTableString, getCreateUserDefinedTypeExtensionsString, getCreateUserDefinedTypeKindString, getCrossReferenceParentTableFilter, getDefaultDecimalPrecision, getDefaultIntervalSecondScale, getDefaultNonContextualLobCreation, getDefaultOrdinalityColumnName, getDefaultProperties, getDefaultUseGetGeneratedKeys, getDisableConstraintsStatement, getDisableConstraintStatement, getDoublePrecision, getDropCatalogCommand, getDropEnumTypeCommand, getDropEnumTypeCommand, getDropForeignKeyString, getDropTableString, getDropUniqueKeyString, getDual, getEnableConstraintsStatement, getEnableConstraintStatement, getEnumTypeDeclaration, getEnumTypeDeclaration, getFallbackSchemaManagementTool, getFloatPrecision, getForeignKeyExporter, getForUpdateNowaitString, getForUpdateNowaitString, getForUpdateSkipLockedString, getForUpdateSkipLockedString, getForUpdateString, getForUpdateString, getForUpdateString, getForUpdateString, getForUpdateString, getForUpdateString, getForUpdateString, getFromDualForSelectOnly, getFunctionalDependencyAnalysisSupport, getGlobalTemporaryTableStrategy, getGroupBySelectItemReferenceStrategy, getHqlTranslator, getIndexExporter, getInformationExtractor, getKeywords, getLobMergeStrategy, getLockingStrategy, getLockingStrategy, getLockRowIdentifier, getLowercaseFunction, getMaxAliasLength, getMaxNVarcharCapacity, getMaxVarbinaryCapacity, getMaxVarbinaryLength, getMaxVarcharCapacity, getMultiKeyLoadSizingStrategy, getNationalizationSupport, getNativeIdentifierGeneratorStrategy, getNativeParameterMarkerStrategy, getNativeValueGenerationStrategy, getNullColumnString, getNullColumnString, getParameterCountLimit, getPersistentTemporaryTableStrategy, getPessimisticLockStyle, getQueryHintString, getReadLockString, getReadLockString, getReadLockString, getReadLockString, getReadRowLockStrategy, getResultSet, getResultSet, getRowIdColumnString, getSchemaNameResolver, getSelectClauseNullString, getSelectClauseNullString, getSequenceInformationExtractor, getSetOperatorSqlString, getSqmTranslatorFactory, getTableCleaner, getTableComment, getTableMigrator, getTableTypeString, getTemporaryTableCreateOptions, getTemporaryTableDdlTransactionHandling, getTemporaryTableDropCommand, getTemporaryTableExporter, getTemporaryTableTruncateCommand, getTimeoutInSeconds, getTruncateTableStatement, getTruncateTableStatements, getUniqueKeyExporter, getUserDefinedTypeExporter, getValueLOBFragmentForExtraCreateTableInfo, getVersion, getWriteLockString, getWriteLockString, getWriteLockString, getWriteLockString, getWriteRowLockStrategy, hasAlterTable, hasSelfReferentialForeignKeyBug, initDefaultProperties, isCurrentTimestampStable, isEmptyStringTreatedAsNull, isJdbcLogWarningsEnabledByDefault, isLob, narrowCastType, ordinal, prependComment, quote, quoteCollation, registerKeyword, registerKeywords, registerResultSetOutParameter, requiresColumnListInCreateView, requiresFloatCastingOfIntegerDivision, requiresNotNullBeforeDefault, requiresParensForTupleCounts, requiresParensForTupleDistinctCounts, resolveSqlTypeCode, resolveSqlTypeCode, resolveSqlTypeLength, rowId, rowIdSqlType, stripsTrailingSpacesFromChar, supportsArrayConstructor, supportsBatchUpdates, supportsBindAsCallableArgument, supportsBindingNullSqlTypeForSetNull, supportsBitType, supportsCascadeDelete, supportsCaseInsensitiveLike, supportsColumnCheck, supportsCommentOn, supportsConflictClauseForInsertCTE, supportsCrossJoin, supportsCteHeaderColumnList, supportsDuplicateSelectItemsInQueryGroup, supportsExceptAll, supportsExpectedLobUsagePattern, supportsFilterClause, supportsForUpdate, supportsFractionalTimestampArithmetic, supportsIfExistsAfterAlterTable, supportsIfExistsAfterConstraintName, supportsIfExistsAfterTableName, supportsIfExistsAfterTypeName, supportsIfExistsBeforeTypeName, supportsInsertReturning, supportsInsertReturningGeneratedKeys, supportsInsertReturningRowId, supportsIntersect, supportsIsTrue, supportsJdbcConnectionLobCreation, supportsJoinInMutationStatementSubquery, supportsLockTimeouts, supportsMaterializedLobAccess, supportsNamedColumnCheck, supportsNamedParameters, supportsNationalizedMethods, supportsNestedSubqueryCorrelation, supportsNestedWithClause, supportsNoColumnsInsert, supportsNotNullAfterGeneratedAs, supportsNoWait, supportsOrderByInSubquery, supportsOrdinalSelectItemReference, supportsOuterJoinForUpdate, supportsPredicateAsExpression, supportsRecursiveCycleClause, supportsRecursiveCycleUsingClause, supportsRecursiveSearchClause, supportsRefCursors, supportsRowConstructor, supportsRowValueConstructorDistinctFromSyntax, supportsRowValueConstructorGtLtSyntax, supportsRowValueConstructorSyntaxInInSubQuery, supportsSkipLocked, supportsStandardArrays, supportsStandardCurrentTimestampFunction, supportsSubqueryInSelect, supportsSubqueryOnMutatingTable, supportsSubselectAsInPredicateLHS, supportsTableCheck, supportsTableOptions, supportsTemporalLiteralOffset, supportsTemporaryTablePrimaryKey, supportsTemporaryTables, supportsTruncateWithCast, supportsTupleCounts, supportsUnboundedLobLocatorMaterialization, supportsUnionAll, supportsUnionInSubquery, supportsUniqueConstraints, supportsUpdateReturning, supportsUserDefinedTypes, supportsValueLOBAccess, supportsValuesListForInsert, supportsWait, supportsWithClause, throttleDdl, toBooleanValueString, toQuotedIdentifier, toString, transformSelectString, unquoteGetGeneratedKeys, useArrayForMultiValuedParameters, useConnectionToCreateLob, useCrossReferenceForeignKeys, useFollowOnLocking, useInputStreamToInsertBlob, useMaterializedLobWhenCapacityExceeded

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • KeycloakSQLServerDialect

      public KeycloakSQLServerDialect()
    • KeycloakSQLServerDialect

      public KeycloakSQLServerDialect(org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo info)
  • Method Details

    • getSqlAstTranslatorFactory

      public org.hibernate.sql.ast.SqlAstTranslatorFactory getSqlAstTranslatorFactory()
      Overrides:
      getSqlAstTranslatorFactory in class org.hibernate.dialect.SQLServerDialect