From 2dbd5431273f7b9d7d97b7d32fd84d88e6e6460a Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Sat, 3 Dec 2016 08:42:46 +1300 Subject: [PATCH] #909 - @Lob with @Size ... produces incorrect DDL for Postgres --- .../config/dbplatform/PostgresPlatform.java | 2 +- .../server/deploy/parse/AnnotationFields.java | 19 ++++++++++--------- .../avaje/tests/model/basic/ContactNote.java | 2 ++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java b/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java index 4c66e09db..085654868 100644 --- a/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java +++ b/src/main/java/com/avaje/ebean/config/dbplatform/PostgresPlatform.java @@ -40,7 +40,7 @@ public class PostgresPlatform extends DatabasePlatform { this.openQuote = "\""; this.closeQuote = "\""; - DbPlatformType dbTypeText = new DbPlatformType("text"); + DbPlatformType dbTypeText = new DbPlatformType("text", false); DbPlatformType dbBytea = new DbPlatformType("bytea", false); dbTypeMap.put(DbType.UUID, new DbPlatformType("uuid", false)); diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationFields.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationFields.java index 86cc0f4b8..89b8d2066 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationFields.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationFields.java @@ -156,12 +156,11 @@ public class AnnotationFields extends AnnotationParser { // determine the JDBC type using Lob/Temporal // otherwise based on the property Class - Lob lob = get(prop, Lob.class); Temporal temporal = get(prop, Temporal.class); if (temporal != null) { readTemporal(temporal, prop); - } else if (lob != null) { + } else if (get(prop, Lob.class) != null) { util.setLobType(prop); } @@ -275,15 +274,17 @@ public class AnnotationFields extends AnnotationParser { prop.setNullable(false); } - // take the max size of all @Size annotations - int maxSize = -1; - for (Size size : getAll(prop, Size.class)) { - if (size.max() < Integer.MAX_VALUE) { - maxSize = Math.max(maxSize, size.max()); + if (!prop.isLob()) { + // take the max size of all @Size annotations + int maxSize = -1; + for (Size size : getAll(prop, Size.class)) { + if (size.max() < Integer.MAX_VALUE) { + maxSize = Math.max(maxSize, size.max()); + } } - } - if (maxSize != -1) { + if (maxSize != -1) { prop.setDbLength(maxSize); + } } } diff --git a/src/test/java/com/avaje/tests/model/basic/ContactNote.java b/src/test/java/com/avaje/tests/model/basic/ContactNote.java index eb95cfb45..29e0d34c1 100644 --- a/src/test/java/com/avaje/tests/model/basic/ContactNote.java +++ b/src/test/java/com/avaje/tests/model/basic/ContactNote.java @@ -3,6 +3,7 @@ package com.avaje.tests.model.basic; import javax.persistence.Entity; import javax.persistence.Lob; import javax.persistence.ManyToOne; +import javax.validation.constraints.Size; @Entity public class ContactNote extends BasicDomain { @@ -14,6 +15,7 @@ public class ContactNote extends BasicDomain { String title; + @Size(max = 2000) @Lob String note;