From 972d2dcc6bdf1f4c64fc8d06d8469126d9d51d97 Mon Sep 17 00:00:00 2001 From: Roland Praml Date: Wed, 30 Aug 2017 07:47:21 +0200 Subject: [PATCH] FIX: nvarchar(max) length specified differently, otherwise this leads to a ddl like this "nvarchar(max)(700)" (#1090) --- src/main/java/io/ebean/config/dbplatform/DbPlatformType.java | 4 +++- .../java/io/ebean/config/dbplatform/DbPlatformTypeParser.java | 3 ++- .../ebean/config/dbplatform/sqlserver/SqlServerPlatform.java | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/ebean/config/dbplatform/DbPlatformType.java b/src/main/java/io/ebean/config/dbplatform/DbPlatformType.java index 52a4491e6..4a65853ff 100644 --- a/src/main/java/io/ebean/config/dbplatform/DbPlatformType.java +++ b/src/main/java/io/ebean/config/dbplatform/DbPlatformType.java @@ -130,7 +130,9 @@ public class DbPlatformType implements ExtraDbTypes { if (canHaveLength || !strict) { // see if there is a precision/scale to add (or not) int len = deployLength != 0 ? deployLength : defaultLength; - if (len > 0) { + if (len == Integer.MAX_VALUE) { + sb.append("(max)"); // TODO: this is sqlserver specific + } else if (len > 0) { sb.append("("); sb.append(len); int scale = deployScale != 0 ? deployScale : defaultScale; diff --git a/src/main/java/io/ebean/config/dbplatform/DbPlatformTypeParser.java b/src/main/java/io/ebean/config/dbplatform/DbPlatformTypeParser.java index b1e37decf..17599cbda 100644 --- a/src/main/java/io/ebean/config/dbplatform/DbPlatformTypeParser.java +++ b/src/main/java/io/ebean/config/dbplatform/DbPlatformTypeParser.java @@ -30,7 +30,8 @@ class DbPlatformTypeParser { } else { String type = columnDefinition.substring(0, openPos); - int scale = Integer.parseInt(columnDefinition.substring(openPos + 1, closePos)); + String strScale = columnDefinition.substring(openPos + 1, closePos); + int scale = strScale.equalsIgnoreCase("max") ? Integer.MAX_VALUE : Integer.parseInt(strScale); return new DbPlatformType(type, scale); } } catch (RuntimeException e) { 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 3ef2a2e0b..cf1652b4c 100644 --- a/src/main/java/io/ebean/config/dbplatform/sqlserver/SqlServerPlatform.java +++ b/src/main/java/io/ebean/config/dbplatform/sqlserver/SqlServerPlatform.java @@ -62,8 +62,8 @@ public class SqlServerPlatform extends DatabasePlatform { dbTypeMap.put(DbType.TIME, new DbPlatformType("time")); dbTypeMap.put(DbType.TIMESTAMP, new DbPlatformType("datetime2")); - dbTypeMap.put(DbType.JSON, new DbPlatformType("nvarchar(max)")); - dbTypeMap.put(DbType.JSONB, new DbPlatformType("nvarchar(max)")); + dbTypeMap.put(DbType.JSON, new DbPlatformType("nvarchar", Integer.MAX_VALUE)); + dbTypeMap.put(DbType.JSONB, new DbPlatformType("nvarchar", Integer.MAX_VALUE)); }