Top Description Inners Fields Constructors Methods
org.hibernate.dialect

public Class SQLServerDialect

extends AbstractTransactSQLDialect
Class Inheritance
Known Direct Subclasses
org.hibernate.dialect.SQLServer2012Dialect, org.hibernate.dialect.SQLServer2016Dialect
Imports
java.sql.DatabaseMetaData, .SQLException, .Types, java.time.temporal.ChronoField, .TemporalAccessor, java.util.Calendar, .Date, .List, .TimeZone, org.hibernate.LockMode, .LockOptions, .QueryTimeoutException, org.hibernate.boot.Metadata, org.hibernate.boot.model.FunctionContributions, .TypeContributions, org.hibernate.boot.model.relational.QualifiedSequenceName, .Sequence, .SqlStringGenerationContext, org.hibernate.dialect.function.CommonFunctionFactory, .CountFunction, .SQLServerFormatEmulation, .SqlServerConvertTruncFunction, org.hibernate.dialect.identity.IdentityColumnSupport, .SQLServerIdentityColumnSupport, org.hibernate.dialect.pagination.LimitHandler, .SQLServer2005LimitHandler, .SQLServer2012LimitHandler, org.hibernate.dialect.sequence.NoSequenceSupport, .SQLServer16SequenceSupport, .SQLServerSequenceSupport, .SequenceSupport, org.hibernate.dialect.unique.AlterTableUniqueIndexDelegate, .UniqueDelegate, org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo, org.hibernate.engine.jdbc.env.spi.IdentifierCaseStrategy, .IdentifierHelper, .IdentifierHelperBuilder, .NameQualifierSupport, org.hibernate.engine.spi.SessionFactoryImplementor, org.hibernate.exception.ConstraintViolationException, .LockTimeoutException, org.hibernate.exception.spi.SQLExceptionConversionDelegate, org.hibernate.internal.util.JdbcExceptionHelper, org.hibernate.mapping.Column, org.hibernate.persister.entity.mutation.EntityMutationTarget, org.hibernate.query.sqm.CastType, .FetchClauseType, .IntervalType, .TemporalUnit, .TrimSpec, org.hibernate.service.ServiceRegistry, org.hibernate.sql.ast.SqlAstNodeRenderingMode, .SqlAstTranslator, .SqlAstTranslatorFactory, org.hibernate.sql.ast.spi.SqlAppender, .StandardSqlAstTranslatorFactory, org.hibernate.sql.ast.tree.Statement, org.hibernate.sql.exec.spi.JdbcOperation, org.hibernate.sql.model.MutationOperation, org.hibernate.sql.model.internal.OptionalTableUpdate, org.hibernate.tool.schema.internal.StandardSequenceExporter, org.hibernate.tool.schema.spi.Exporter, org.hibernate.type.BasicType, .BasicTypeRegistry, .StandardBasicTypes, org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType, org.hibernate.type.descriptor.jdbc.JdbcType, .TimestampUtcAsJdbcTimestampJdbcType, .TinyIntAsSmallIntJdbcType, .UUIDJdbcType, .XmlJdbcType, org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry, org.hibernate.type.descriptor.sql.internal.DdlTypeImpl, org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry, jakarta.persistence.TemporalType

A dialect for Microsoft SQL Server 2008 and above
Author
Gavin King

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final StandardSequenceExporter
private static final int
private static final int
private static final DatabaseVersion
private static final int
PARAM_LIST_SIZE_LIMIT

NOTE : 2100 is the documented limit supposedly - but in my testing, sending 2100 parameters fails saying it must be less than 2100.

private final UniqueDelegate

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public void
appendBinaryLiteral(SqlAppender appender, byte[] bytes)

Overrides org.hibernate.dialect.AbstractTransactSQLDialect.appendBinaryLiteral.

Append a binary literal to the given SqlAppender.
public void
appendDatetimeFormat(SqlAppender appender, String format)

Overrides org.hibernate.dialect.Dialect.appendDatetimeFormat.

Translate the given datetime format string from the pattern language defined by Java's java.time.format.DateTimeFormatter to whatever pattern language is understood by the native datetime formatting function for this database (often the to_char() function).
public void
appendDateTimeLiteral(SqlAppender appender, TemporalAccessor temporalAccessor, TemporalType precision, TimeZone jdbcTimeZone)

Overrides org.hibernate.dialect.Dialect.appendDateTimeLiteral.

Append a datetime literal representing the given java.time value to the given SqlAppender.
public void
appendDateTimeLiteral(SqlAppender appender, Date date, TemporalType precision, TimeZone jdbcTimeZone)

Overrides org.hibernate.dialect.Dialect.appendDateTimeLiteral.

Append a datetime literal representing the given Date value to the given SqlAppender.
public void
appendDateTimeLiteral(SqlAppender appender, Calendar calendar, TemporalType precision, TimeZone jdbcTimeZone)

Overrides org.hibernate.dialect.Dialect.appendDateTimeLiteral.

Append a datetime literal representing the given Calendar value to the given SqlAppender.
public String
appendLockHint(LockOptions
The lock options to apply
lockOptions
,
String
The name of the table to which to apply the lock hint.
tableName
)

Overrides org.hibernate.dialect.AbstractTransactSQLDialect.appendLockHint.

Some dialects support an alternative means to SELECT FOR UPDATE, whereby a "lock hint" is appended to the table name in the from clause.
public void
appendUUIDLiteral(SqlAppender appender, UUID literal)

Overrides org.hibernate.dialect.Dialect.appendUUIDLiteral.

Append a literal SQL uuid representing the given Java UUID.
public IdentifierHelper
buildIdentifierHelper(IdentifierHelperBuilder
A partially-configured IdentifierHelperBuilder.
builder
,
DatabaseMetaData
Access to the metadata returned from the driver if needed and if available

Warning

it may be null.

dbMetaData
)

Overrides org.hibernate.dialect.Dialect.buildIdentifierHelper.

The IdentifierHelper indicated by this dialect for handling identifier conversions.
public SQLExceptionConversionDelegate
public String
castPattern(CastType
a CastType indicating the type of the value argument
from
,
CastType
a CastType indicating the type the value argument is cast to
to
)

Overrides org.hibernate.dialect.Dialect.castPattern.

Obtain a pattern for the SQL equivalent to a cast() function call.
protected String
castType(int
The JDBC type code representing the target type
sqlTypeCode
)

Overrides org.hibernate.dialect.Dialect.castType.

The SQL type to use in cast( ...
public char
closeQuote()

Overrides org.hibernate.dialect.Dialect.closeQuote.

The character specific to this dialect used to close a quoted identifier.
protected String
columnType(int
a SQL type code
sqlTypeCode
)

Overrides org.hibernate.dialect.AbstractTransactSQLDialect.columnType.

The database column type name for a given JDBC type code defined in Types or SqlTypes.
public void
contributeTypes(TypeContributions
Callback to contribute the types
typeContributions
,
ServiceRegistry
The service registry
serviceRegistry
)

Overrides org.hibernate.dialect.Dialect.contributeTypes.

A callback which allows the Dialect to contribute types.
public MutationOperation
createOptionalTableUpdateOperation(EntityMutationTarget mutationTarget, OptionalTableUpdate optionalTableUpdate, SessionFactoryImplementor factory)

Overrides org.hibernate.dialect.Dialect.createOptionalTableUpdateOperation.

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
Create a MutationOperation for a updating an optional table
private StandardSequenceExporter
public String
currentDate()

Overrides org.hibernate.dialect.Dialect.currentDate.

Translation of the HQL/JPQL current_date function, which maps to the Java type java.sql.Date, and of the HQL local_date function which maps to the Java type java.time.LocalDate.
public String
currentTime()

Overrides org.hibernate.dialect.Dialect.currentTime.

Translation of the HQL/JPQL current_time function, which maps to the Java type java.sql.Time which is a time with no time zone.
public String
currentTimestamp()

Overrides org.hibernate.dialect.Dialect.currentTimestamp.

Translation of the HQL/JPQL current_timestamp function, which maps to the Java type java.sql.Timestamp which is a datetime with no time zone.
public String
currentTimestampWithTimeZone()

Overrides org.hibernate.dialect.Dialect.currentTimestampWithTimeZone.

Translation of the HQL offset_datetime function, which maps to the Java type java.time.OffsetDateTime which is a datetime with a time zone.
public static Replacer
public boolean
doesReadCommittedCauseWritersToBlockReaders()

Overrides org.hibernate.dialect.AbstractTransactSQLDialect.doesReadCommittedCauseWritersToBlockReaders.

For the underlying database, is READ_COMMITTED isolation implemented by forcing readers to wait for write locks to be released?
public boolean
doesRepeatableReadCauseReadersToBlockWriters()

Overrides org.hibernate.dialect.AbstractTransactSQLDialect.doesRepeatableReadCauseReadersToBlockWriters.

For the underlying database, is REPEATABLE_READ isolation implemented by forcing writers to wait for read locks to be released?
public String
extractPattern(TemporalUnit
the first argument
unit
)

Overrides org.hibernate.dialect.Dialect.extractPattern.

Obtain a pattern for the SQL equivalent to an extract() function call.
public String
generatedAs(String
a SQL expression used to generate the column value
generatedAs
)

Overrides org.hibernate.dialect.Dialect.generatedAs.

The generated as clause, or similar, for generated column declarations in DDL statements.
public String
getAlterColumnTypeString(String
the name of the column
columnName
,
String
the new type of the column
columnType
,
String
the full column definition
columnDefinition
)

Overrides org.hibernate.dialect.Dialect.getAlterColumnTypeString.

The fragment of an alter table command which modifies a column type, or null if column types cannot be modified.
public String
getCreateIndexString(boolean
true if the index is a unique index
unique
)

Overrides org.hibernate.dialect.Dialect.getCreateIndexString.

The command used to create an index, usually create index or create unique index.
public String
getCreateIndexTail(boolean unique, List<Column> columns)

Overrides org.hibernate.dialect.Dialect.getCreateIndexTail.

A string to be appended to the end of the create index command, usually to specify that null values are to be considered distinct.
public String
getCreateTemporaryTableColumnAnnotation(int
The SQL type code
sqlTypeCode
)

Overrides org.hibernate.dialect.Dialect.getCreateTemporaryTableColumnAnnotation.

Annotation to be appended to the end of each COLUMN clause for temporary tables.
public String
getCurrentSchemaCommand()

Overrides org.hibernate.dialect.Dialect.getCurrentSchemaCommand.

Get the SQL command used to retrieve the current schema name.
public String
getCurrentTimestampSelectString()

Overrides org.hibernate.dialect.AbstractTransactSQLDialect.getCurrentTimestampSelectString.

The current_timestamp is more accurate, but only known to be supported in SQL Server 7.0 and later and Sybase not known to support it at all

The command used to retrieve the current timestamp from the database.

public long
getDefaultLobLength()

Overrides org.hibernate.dialect.Dialect.getDefaultLobLength.

The default length for a LOB column, if LOB columns have a length in this dialect.
public int
getDefaultTimestampPrecision()

Overrides org.hibernate.dialect.Dialect.getDefaultTimestampPrecision.

SQL server supports up to 7 decimal digits of fractional second precision in a datetime2, but since its duration arithmetic functions try to fit durations into an int, which is impossible with such high precision, so default to generating datetime2(3) columns.
public String[]
getDropSchemaCommand(String
The name of the schema to be dropped.
schemaName
)

Overrides org.hibernate.dialect.Dialect.getDropSchemaCommand.

Get the SQL command used to drop the named schema.
public long
getFractionalSecondPrecisionInNanos()

Overrides org.hibernate.dialect.Dialect.getFractionalSecondPrecisionInNanos.

SQL server supports up to 7 decimal digits of fractional second precision in datetime2, but unfortunately its duration arithmetic functions have a nasty habit of overflowing.
public IdentityColumnSupport
public int
getInExpressionCountLimit()

Overrides org.hibernate.dialect.Dialect.getInExpressionCountLimit.

Return the limit that the underlying database places on the number of elements in an IN predicate.
public LimitHandler
public int
getMaxIdentifierLength()

Overrides org.hibernate.dialect.Dialect.getMaxIdentifierLength.

What is the maximum identifier length supported by this dialect?
public int
getMaxNVarcharLength()

Overrides org.hibernate.dialect.Dialect.getMaxNVarcharLength.

The biggest size value that can be supplied as argument to a java.sql.Types#NVARCHAR-like type.
public int
getMaxVarcharLength()

Overrides org.hibernate.dialect.Dialect.getMaxVarcharLength.

The biggest size value that can be supplied as argument to a java.sql.Types#VARCHAR-like type.
protected DatabaseVersion
getMinimumSupportedVersion()

Overrides org.hibernate.dialect.Dialect.getMinimumSupportedVersion.

Get the version of the SQL dialect that is the minimum supported by this implementation.
public NameQualifierSupport
public String
getNoColumnsInsertString()

Overrides org.hibernate.dialect.Dialect.getNoColumnsInsertString.

The fragment used to insert a row without specifying any column values, usually just (), but sometimes default values.
public String
getQueryHintString(String
The query to which to apply the hint.
sql
,
String
The hints to apply
hints
)

Overrides org.hibernate.dialect.Dialect.getQueryHintString.

Apply a hint to the given SQL query.
public String
getQuerySequencesString()

Overrides org.hibernate.dialect.Dialect.getQuerySequencesString.

Get the select command used retrieve the names of all sequences.
public Exporter<Sequence>
public SequenceSupport
public SqlAstTranslatorFactory
public TimeZoneSupport
public UniqueDelegate
public boolean
hasDataTypeBeforeGeneratedAs()

Overrides org.hibernate.dialect.Dialect.hasDataTypeBeforeGeneratedAs.

Is an explicit column type required for generated as columns?
public void
initializeFunctionRegistry(FunctionContributions functionContributions)

Overrides org.hibernate.dialect.AbstractTransactSQLDialect.initializeFunctionRegistry.

Initialize the given registry with any dialect-specific functions.
public char
openQuote()

Overrides org.hibernate.dialect.Dialect.openQuote.

The character specific to this dialect used to begin a quoted identifier.
protected void
registerColumnTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry)

Overrides org.hibernate.dialect.Dialect.registerColumnTypes.

Register ANSI-standard column types using the length limits defined by getMaxVarcharLength(), getMaxNVarcharLength(), and getMaxVarbinaryLength().
protected void
registerDefaultKeywords()

Overrides org.hibernate.dialect.Dialect.registerDefaultKeywords.

Register the reserved words of ANSI-standard SQL as keywords.
public JdbcType
resolveSqlTypeDescriptor(String
the column type name
columnTypeName
,
int jdbcTypeCode, int
the precision or 0
precision
,
int
the scale or 0
scale
,
JdbcTypeRegistry jdbcTypeRegistry)

Overrides org.hibernate.dialect.AbstractTransactSQLDialect.resolveSqlTypeDescriptor.

Assigns an appropriate JdbcType to a column of a JDBC result set based on the column type name, JDBC type code, precision, and scale.
public boolean
supportsAlterColumnType()

Overrides org.hibernate.dialect.Dialect.supportsAlterColumnType.

Does this dialect support modifying the type of an existing column?
public boolean
supportsCircularCascadeDeleteConstraints()

Overrides org.hibernate.dialect.Dialect.supportsCircularCascadeDeleteConstraints.

Does this dialect support definition of cascade delete constraints which can cause circular chains?
public boolean
supportsDistinctFromPredicate()

Overrides org.hibernate.dialect.Dialect.supportsDistinctFromPredicate.

Does this dialect support some kind of distinct from predicate?
public boolean
supportsFetchClause(FetchClauseType
The fetch clause type
type
)

Overrides org.hibernate.dialect.Dialect.supportsFetchClause.

Does this dialect support the given FETCH clause type.
public boolean
supportsIfExistsBeforeConstraintName()

Overrides org.hibernate.dialect.Dialect.supportsIfExistsBeforeConstraintName.

For dropping a constraint with an alter table statement, can the phrase if exists be applied before the constraint name?
public boolean
supportsIfExistsBeforeTableName()

Overrides org.hibernate.dialect.Dialect.supportsIfExistsBeforeTableName.

For dropping a table, can the phrase if exists be applied before the table name?
public boolean
supportsLateral()

Overrides org.hibernate.dialect.Dialect.supportsLateral.

Does this dialect support the SQL lateral keyword or a proprietary alternative?
public boolean
supportsLobValueChangePropagation()

Overrides org.hibernate.dialect.Dialect.supportsLobValueChangePropagation.

Does the dialect support propagating changes to LOB values back to the database?
public boolean
public boolean
supportsNonQueryWithCTE()

Overrides org.hibernate.dialect.Dialect.supportsNonQueryWithCTE.

Does this dialect support insert, update, and delete statements with Common Table Expressions (CTEs)?
public boolean
supportsNoWait()

Overrides org.hibernate.dialect.Dialect.supportsNoWait.

Does this dialect support NO_WAIT timeout.
public boolean
supportsNullPrecedence()

Overrides org.hibernate.dialect.Dialect.supportsNullPrecedence.

Does this dialect support nulls first and nulls last?
public boolean
supportsOffsetInSubquery()

Overrides org.hibernate.dialect.Dialect.supportsOffsetInSubquery.

Does this dialect support offset in subqueries?
public boolean
supportsRecursiveCTE()

Overrides org.hibernate.dialect.Dialect.supportsRecursiveCTE.

Does this dialect/database support recursive CTEs?
public boolean
supportsResultSetPositionQueryMethodsOnForwardOnlyCursor()

Overrides org.hibernate.dialect.Dialect.supportsResultSetPositionQueryMethodsOnForwardOnlyCursor.

Does this dialect support asking the result set its positioning information on forward-only cursors?
public boolean
supportsSkipLocked()

Overrides org.hibernate.dialect.Dialect.supportsSkipLocked.

Does this dialect support SKIP_LOCKED timeout.
public boolean
supportsValuesList()

Overrides org.hibernate.dialect.Dialect.supportsValuesList.

Does this dialect support values lists of form VALUES (1), (2), (3)?
public boolean
supportsWait()

Overrides org.hibernate.dialect.Dialect.supportsWait.

Does this dialect support WAIT timeout.
public boolean
supportsWindowFunctions()

Overrides org.hibernate.dialect.Dialect.supportsWindowFunctions.

Does this dialect support window functions like row_number() over (..)?
public String
timestampaddPattern(TemporalUnit
The unit to add to the temporal
unit
,
TemporalType
The type of the temporal
temporalType
,
IntervalType
The type of interval to add or null if it's not a native interval
intervalType
)

Overrides org.hibernate.dialect.Dialect.timestampaddPattern.

Obtain a pattern for the SQL equivalent to a timestampadd() function call.
public String
timestampdiffPattern(TemporalUnit
the first argument
unit
,
TemporalType
true if the first argument is a timestamp, false if a date
fromTemporalType
,
TemporalType
true if the second argument is
toTemporalType
)

Overrides org.hibernate.dialect.Dialect.timestampdiffPattern.

Obtain a pattern for the SQL equivalent to a timestampdiff() function call.
public String
translateDurationField(TemporalUnit unit)

Overrides org.hibernate.dialect.Dialect.translateDurationField.

Return the name used to identify the given unit of duration as an argument to #timestampadd() or #timestampdiff(), or of this dialect's equivalent functions.
public String
translateExtractField(TemporalUnit unit)

Overrides org.hibernate.dialect.Dialect.translateExtractField.

Return the name used to identify the given field as an argument to the extract() function, or of this dialect's equivalent function.
public String
trimPattern(TrimSpec specification, boolean
true if the trim character is a whitespace and can be omitted, false if it must be explicit and a ?2 placeholder should be included in the pattern
isWhitespace
)

Overrides org.hibernate.dialect.AbstractTransactSQLDialect.trimPattern.

Obtain a pattern for the SQL equivalent to a trim() function call.
Inherited from org.hibernate.dialect.AbstractTransactSQLDialect:
applyLocksToSqlgetAddColumnStringgetDefaultStatementBatchSizegetFallbackSqmInsertStrategygetFallbackSqmMutationStrategygetForUpdateStringgetNullOrderinggetPreferredSqlTypeCodeForBooleangetResultSetgetSelectGUIDStringgetSupportedTemporaryTableKindgetTemporaryTableAfterUseActiongetTemporaryTableBeforeUseActiongetTemporaryTableCreateCommandgetWriteRowLockStrategyisCurrentTimestampSelectStringCallablequalifyIndexNameregisterResultSetOutParameterreplaceLtrimRtrimreplaceLtrimRtrimrequiresCastForConcatenatingNonStringssupportsCurrentTimestampSelectionsupportsExistsInSelectsupportsPartitionBysupportsTupleDistinctCounts