From 9953ef35ebb9aa335ce481da12bc004bfde79b39 Mon Sep 17 00:00:00 2001 From: Roland Praml Date: Wed, 28 Feb 2018 21:41:04 +0100 Subject: [PATCH] ENH: native UUID-support for SqlServer --- .../ebean/config/dbplatform/sqlserver/SqlServerPlatform.java | 4 ++++ .../io/ebeaninternal/server/type/ScalarTypeUUIDNative.java | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/io/ebean/config/dbplatform/sqlserver/SqlServerPlatform.java b/src/main/java/io/ebean/config/dbplatform/sqlserver/SqlServerPlatform.java index 31e1a8525..d38c06eae 100644 --- a/src/main/java/io/ebean/config/dbplatform/sqlserver/SqlServerPlatform.java +++ b/src/main/java/io/ebean/config/dbplatform/sqlserver/SqlServerPlatform.java @@ -31,6 +31,7 @@ public class SqlServerPlatform extends DatabasePlatform { this.sqlLimiter = new SqlServerSqlLimiter(); this.basicSqlLimiter = new SqlServerBasicSqlLimiter(); this.historySupport = new SqlServerHistorySupport(); + this.nativeUuidType = true; this.dbIdentity.setIdType(IdType.IDENTITY); this.dbIdentity.setSupportsGetGeneratedKeys(true); this.dbIdentity.setSupportsIdentity(true); @@ -83,6 +84,9 @@ public class SqlServerPlatform extends DatabasePlatform { if (dbIdentity.getIdType() == IdType.SEQUENCE) { this.persistBatchOnCascade = PersistBatch.ALL; } + if (nativeUuidType && config.getDbTypeConfig().getDbUuid().useNativeType()) { + dbTypeMap.put(DbType.UUID, new DbPlatformType("uniqueidentifier", false)); + } } @Override diff --git a/src/main/java/io/ebeaninternal/server/type/ScalarTypeUUIDNative.java b/src/main/java/io/ebeaninternal/server/type/ScalarTypeUUIDNative.java index cf96f2704..fc4600ed4 100644 --- a/src/main/java/io/ebeaninternal/server/type/ScalarTypeUUIDNative.java +++ b/src/main/java/io/ebeaninternal/server/type/ScalarTypeUUIDNative.java @@ -20,6 +20,9 @@ public class ScalarTypeUUIDNative extends ScalarTypeUUIDBase { if (value == null) { return null; } + if (value instanceof String) { + return UUID.fromString((String) value); + } return (UUID) value; }