Skip to content

Commit caa84d3

Browse files
knutwannhedenSanne
authored andcommitted
HHH-13999 Support SQL Server 2016
SQL Server 2016 (13.x) and later support the `if exists` clause for most `drop` DDL statements. The new `SQLServer2016Dialect` dialect accounts for this and offers the advantage that no error messages get logged when using `hibernate.hbm2ddl.auto=create-drop`.
1 parent 0cbf0e5 commit caa84d3

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/Database.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public Dialect resolveDialect(DialectResolutionInfo info) {
480480
SQLSERVER {
481481
@Override
482482
public Class<? extends Dialect> latestDialect() {
483-
return SQLServer2012Dialect.class;
483+
return SQLServer2016Dialect.class;
484484
}
485485

486486
@Override
@@ -501,16 +501,20 @@ public Dialect resolveDialect(DialectResolutionInfo info) {
501501
return new SQLServer2008Dialect();
502502
}
503503
case 11:
504-
case 12:
505-
case 13: {
504+
case 12: {
506505
return new SQLServer2012Dialect();
507506
}
507+
case 13:
508+
case 14:
509+
case 15: {
510+
return new SQLServer2016Dialect();
511+
}
508512
default: {
509513
if ( majorVersion < 8 ) {
510514
return new SQLServerDialect();
511515
}
512516
else {
513-
// assume `majorVersion > 13`
517+
// assume `majorVersion > 15`
514518
return latestDialectInstance( this );
515519
}
516520
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.dialect;
8+
9+
/**
10+
* Microsoft SQL Server 2016 Dialect
11+
*/
12+
public class SQLServer2016Dialect extends SQLServer2012Dialect {
13+
14+
@Override
15+
public boolean supportsIfExistsBeforeTableName() {
16+
return true;
17+
}
18+
19+
@Override
20+
public boolean supportsIfExistsBeforeConstraintName() {
21+
return true;
22+
}
23+
24+
@Override
25+
public String getDropSequenceString(String sequenceName) {
26+
return "drop sequence if exists " + sequenceName;
27+
}
28+
29+
@Override
30+
public String[] getDropSchemaCommand(String schemaName) {
31+
return new String[] {"drop schema if exists " + schemaName};
32+
}
33+
}

0 commit comments

Comments
 (0)